[英]How to send the disabled element value to server?
我有下一个复选框:
<input type="checkbox" value="true" name="permanentEmployee" checked="" id="permanentEmployee" disabled="">
我给自己定的属性disabled
为true,并提交表单
$("#permanentEmployee").prop('disabled', true);`
在服务器端,如果我这样做:
request.getParameter("permanentEmployee")
我得到的值为Null ,但是如果不禁用复选框,则会得到正确的值(即True )。 为什么即使选中了禁用复选框值也无法将其设置为True ?
禁用的表单元素不会通过表单提交发送。
您可以考虑改用只读
一个想法是
$('#permanentEmployee').click(function(){
return false; // even if the user clicks on it it will not change
});
$('#permanentEmployee').prop('checked', true);
在提交表单(提交提交侦听器)之前,您可以启用该复选框。
禁用的复选框(可能还有其他表单元素)不会发送到服务器。
这里有两个解决方案: 如何确保禁用<select>表单字段时提交?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.