如何将禁用的元素值发送到服务器

How to send the disabled element value to server?

本文关键字:服务器 元素      更新时间:2023-09-26

我有下一个复选框:

<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);
http://jsfiddle.net/Spokey/M3LfA/1/

在提交表单(onsubmit侦听器)之前,您可以启用复选框

禁用的复选框(可能还有其他表单元素)不会发送到服务器。

这里有两个解决方案:如何确保