我有一个带有自定义设计的复选框(使用 CSS)的表单,我想将其状态传递到 JSP 页面以保存到数据库。
这是我的复选框的代码:
<div class="checkbox" title="Automatically activate microphone"> <span class="box" role="checkbox" aria-checked="true" tabindex="17" aria-labelledby="setting1"></span>
<label class="checkmark"></label>
<label class="text" id="setting1">Automatically activate microphone.</label>
</div>
我可以使用 JavaScript 获取复选框的状态,但我不确定如何将该值传递到我的 JSP 页面进行处理。
最佳答案
您可以使用隐藏的输入类型,其值与复选框值相同
<div class="checkbox" title="Automatically activate microphone"> <span class="box" role="checkbox" aria-checked="true" tabindex="17" aria-labelledby="setting1"></span>
<label class="checkmark"></label>
<label class="text" id="setting1">Automatically activate microphone.</label>
<input type = "hidden" value = "checkBoxValue" name = "someName">
</div>
您可以使用 JavaScript 根据复选框状态更改隐藏类型的值
现在提交表单后,您可以使用 EL requestScope['someName']
访问 JSP 中的复选框值或request.getParameter("someName")
关于javascript - 如何将自定义设计的复选框的状态传递到 JSP 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18190526/