Javascript JSTL复选框不工作
情况: 当我们勾选复选框时,发送一个post请求,复选框值为false 在验证中,我们将模型设置为true 问题Javascript JSTL复选框不工作,javascript,jquery,spring,checkbox,jstl,Javascript,Jquery,Spring,Checkbox,Jstl,情况: 当我们勾选复选框时,发送一个post请求,复选框值为false 在验证中,我们将模型设置为true 问题 但是问题是这个模型对象(也是一个会话属性)没有在jsp上反映这种变化。所以问题是obj.value在这两种情况下都是假的 <div class="block"> <label class="medium">Attach authority:</label> <input type="checkbox" value="${Model.noti
但是问题是这个模型对象(也是一个会话属性)没有在jsp上反映这种变化。所以问题是obj.value在这两种情况下都是假的
<div class="block">
<label class="medium">Attach authority:</label>
<input type="checkbox" value="${Model.noticeDetailsModel.fullAuthority}"
<c:if test="${Model.noticeDetailsModel.fullAuthority}">checked="checked"</c:if>
id="fullAuthority" onchange="javascript: setNoticeDetails(this);"/>
</div>
//set up details
function setNoticeDetails(obj) {
$.post("generateNotice.do", {
value : obj.value,
name : obj.id,
stage : "setNoticeDetails"
});
}
附呈当局:
//设置详细信息
功能设置通知详细信息(obj){
$.post(“generateNotice.do”{
值:obj.value,
姓名:obj.id,
阶段:“SetNotifiedDetails”
});
}
情况2:当我们勾选复选框时,在发送第一个请求后,post请求再次发送,复选框值为false而不是true(因为我们在模型对象即“model”中将值设置为true)。由于我看不到控制器代码,我假设java端,即post请求的接收工作正常 然而: 函数
setNoticeDetails
发送一个ajax请求,该请求的响应被代码忽略,因为您尚未实现成功处理程序。有关更多详细信息,请参阅
因此,由于这是一个ajax请求,因此不会重新加载html/页面-而是应该通过javascript操作html-例如,如果您只想更改复选框的值,请执行以下操作:
function setNoticeDetails(obj) {
$.post("generateNotice.do", {
value : obj.value,
name : obj.id,
stage : "setNoticeDetails",
success: function(data) {
if ( $("#fullAuthority").val() === "true" ){
$("#fullAuthority").val("false");
} else {
$("#fullAuthority").val("true");
}
}
});
}