【问题标题】:JavaScript Submithandler IssueJavaScript 提交处理程序问题
【发布时间】:2011-12-07 04:20:36
【问题描述】:
 $("#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;
        }
    });

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

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

【问题讨论】:

    标签: javascript jquery form-submit


    【解决方案1】:

    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 中描述的方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      • 2022-07-01
      • 1970-01-01
      • 2010-10-27
      相关资源
      最近更新 更多