[英]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.