JavaScript提交处理程序问题

JavaScript Submithandler Issue

本文关键字:问题 程序 处理 提交 JavaScript      更新时间:2023-09-26
 $("#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;
        }
    });

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

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

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()文档中描述的方式。