【问题标题】:JSTL checkbox not workingJSTL 复选框不起作用
【发布时间】:2014-06-13 04:52:17
【问题描述】:

情况: 当我们勾选复选框时,发送一个 post 请求,复选框值为 false 我们在验证中将 Model 设置为 true。

问题
但问题是这个模型对象也是一个会话属性,并没有反映 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"
    });
}

情况 2:当我们勾选复选框时,在发送第一个请求后,再次发送一个 post 请求,复选框值为 false 而不是 true(因为我们在模型对象中将值设置为 true,即“Model”)

【问题讨论】:

    标签: javascript jquery spring checkbox jstl


    【解决方案1】:

    由于我看不到控制器代码,我假设 java 端,即接收 post 请求工作正常

    然而:

    您的函数setNoticeDetails 发送一个ajax 请求,您的代码将忽略该请求的响应,因为您没有实现成功处理程序。有关详细信息,请参阅http://api.jquery.com/jquery.post/

    因此,由于它是一个 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");
                 }
            } 
            }); 
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-04
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多