简体   繁体   English

禁用Spring中的复选框并将检查的值传递给控制器

[英]Disable a checkbox in spring and pass the checked value to controller

Hello I have to disable checkbox in spring html form and pass the checked value to controller. 您好,我必须禁用spring html格式的复选框,然后将检查的值传递给控制器​​。 I use the below code, but the problem is that I am not able to pass the checked value to controller when the disabled attribute is set to true 我使用以下代码,但是问题是,当disable属性设置为true时,我无法将检查值传递给控制器

<form:checkbox path="agreementCats" disabled="true" value="${x.value}" class="category-checkboxes" id="agreementCat-cb-${i.index}" /><label class="control-label" for="agreementCat-cb-${i.index}">&nbsp;${x.label}</label>
<form:hidden path="agreementCats" value="${x.value}" />

The above code sends all the values to controller. 上面的代码将所有值发送到控制器。 Please help!! 请帮忙!!

代替disabled="true"将其更改为readonly= "true"如果您插入,Disabled不会发送值,但是readonly会发送值。

in HTML have two tag with similar meaning but different context is Disabled and ReadOnly. HTML中的两个标签具有相似的含义,但是不同的上下文是Disabled和ReadOnly。

  • disabled : Disabled the input in the form and the data isn't in form query. disable :禁用表单中的输入,并且数据不在表单查询中。
  • readonly : Omit the user UI interaction but the input is in form query. readonly :省略用户UI交互,但输入形式为表单查询。

Try use readonly tag instead disabled, I hope this help you. 尝试使用readonly标签代替禁用标签,希望对您有所帮助。

That solution works for all inputs except checkbox ... Checkbox can't use readonly, but you can do a little trick, is a dirt trick, but it can you help to not permit user touch check box. 该解决方案适用于除复选框以外的所有输入 。复选框不能使用只读,但是您可以做一些技巧,这是一个肮脏的技巧,但是它可以帮助您禁止用户触摸复选框。

If you know in server side what checkbox can be edited, try this code: 如果您知道在服务器端可以编辑哪个复选框,请尝试以下代码:

<input type="checkbox" <c:if test="condition">onclick="return false;"</c:if> ></input>

That code not permit user click the checkbox if the condition is true. 如果条件为真,则该代码不允许用户单击复选框。 Maybe with this can solved your problem. 也许与此可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM