how to disable buttons based on a condition in jsp?

前端 未结 4 825
一生所求
一生所求 2020-12-06 07:52

how can I disable a button by checking a condition in my jsp? If true,then the button is enabled,if false,then the button is disabled. The condition would be checking the va

相关标签:
4条回答
  • 2020-12-06 08:03

    Or simply you could do it using el directly like this:

    <input type="button" ${ condition ? 'disabled="disabled"' : ''}/>
    

    As an example:

    <input type="button" ${ someVariable eq 5  ? 'disabled="disabled"' : ''}/>
    
    0 讨论(0)
  • 2020-12-06 08:10

    Try using JSTL construction like this:

    <input type="button" <c:if test="${variable == false}"><c:out value="disabled='disabled'"/></c:if>">
    

    For more examples see http://www.ibm.com/developerworks/java/library/j-jstl0211/index.html

    0 讨论(0)
  • 2020-12-06 08:18

    My approach would be something like this:

     <c:choose>
        <c:when test="${condition == true}">
          <input type="button" disabled="disabled"/>
        </c:when>
        <c:otherwise>
          <input type="button" />
        </c:otherwise>
     </c:choose>
    
    0 讨论(0)
  • 2020-12-06 08:24

    If you use Spring's form tag library, you could also write:

    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    
    <form:form>
     ...
     <form:button type="button" disabled="${condition}">Name of button</form:button>
    </form:form>
    
    0 讨论(0)
提交回复
热议问题