JavaScript Submithandler问题

时间:2011-10-13 17:52:44

标签: javascript jquery form-submit

 $("#myform").validate({
        submitHandler: function (form) {
            var cboxes = ($('input:checkbox:checked').filter(":checked").length);
            var nboxes = ($(":checkbox:not(:checked)").length);
            var flag = false;
            if ((cboxes > 0) && (nboxes > 0)) {
                flag = confirm('You have Checked only few locations among the List. \n Are you sure, you do not want to Prescribe from the other locations? ');
            } else if (cboxes == 0) {
                alert('Please select atleast One Address \n Where you would prefer to prescribe from.');
            }
            else {
                flag = true;
            }
            return flag;
        }
    });

如果我点击确定弹出确认框,它应该接受提交,但不是。

有谁能告诉我为什么会这样?

1 个答案:

答案 0 :(得分:2)

return flag替换为form.submit

$("#myform").validate({
    submitHandler: function (form) {
        var cboxes = ($('input:checkbox:checked').filter(":checked").length);
        var nboxes = ($(":checkbox:not(:checked)").length);
        var flag = false;
        if ((cboxes > 0) && (nboxes > 0)) {
            flag = confirm('You have Checked only few locations among the List. \n Are you sure, you do not want to Prescribe from the other locations? ');
        } else if (cboxes == 0) {
            alert('Please select atleast One Address \n Where you would prefer to prescribe from.');
        }
        else {
            flag = true;
        }

        if(flag)
            form.submit();
    }
});

如果你没有使用AJAX,这就是.validate() docs中描述的方式。