10

在我的 jsp 中,对于某些条件,我希望复选框存在,但不想让用户选中或取消选中它。

我不确定如何实现这一目标。我尝试了以下

<form:checkbox path="..." disabled = "disabled"> 
<form:checkbox path="..." disabled = "true"> 
<form:checkbox path="..." readonly = "readonly"> 

似乎没有任何工作。

有人可以对此有所了解吗?

谢谢..

4

1 回答 1

21

disabled属性 in<spring:checkbox>应该设置为trueorfalse并且复选框没有readonly属性。所以

<form:checkbox path="corespondingPath" disabled = "true">   

应该管用。

很少链接
Spring doc 链接。
Spring表单输入中的只读和禁用属性

您可以根据某些条件使用 JSTL 添加它

<c:choose>
    <c:when test="${condition}">
          // Add checkbox with disabled="true"
          <form:checkbox path="desiredPAth" disabled="true" />
    </c:when>
    <c:otherwise>
          // Do something else
    </c:otherwise>
</c:choose>   
于 2012-07-24T06:20:52.273 回答