JavaScript 提交处理程序问题

发布于 2024-12-09 11:10:16 字数 818 浏览 0 评论 0原文

 $("#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;
        }
    });

当弹出确认框时,如果我单击“确定”,它应该接受提交,但事实并非如此。

谁能告诉我为什么会发生这种情况?

 $("#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;
        }
    });

When the Confirm box pop up if I clicks ok it should accept the submit, but it is not.

Can anyone tell me why is this happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月牙弯弯 2024-12-16 11:10:16

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

Replace return flag with 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();
    }
});

If you're not using AJAX, this is the way described in the .validate() docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文