Javascript 如何根据jsp中的条件禁用按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6633059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to disable buttons based on a condition in jsp?
提问by Kazekage Gaara
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 value of a variable. I know how to disable a button using javascript, but to use it along with the condition in jsp is what I'm not able to figure out. Is it at all possible?
如何通过检查我的 jsp 中的条件来禁用按钮?如果为真,则启用该按钮,如果为假,则禁用该按钮。条件是检查变量的值。我知道如何使用 javascript 禁用按钮,但是将它与 jsp 中的条件一起使用是我无法弄清楚的。有可能吗?
回答by Eugene Burtsev
Try using JSTL construction like this:
尝试使用这样的 JSTL 构造:
<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
有关更多示例,请参阅http://www.ibm.com/developerworks/java/library/j-jstl0211/index.html
回答by fujy
Or simply you could do it using el
directly like this:
或者干脆你可以el
像这样直接使用它:
<input type="button" ${ condition ? 'disabled="disabled"' : ''}/>
As an example:
举个例子:
<input type="button" ${ someVariable eq 5 ? 'disabled="disabled"' : ''}/>
回答by kukudas
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>