1

我是第一次使用 AJAX/jQuery,并且正在慢慢了解它。

我有有效的表单验证以及按下提交时的确认按钮。问题是即使表单尚未完成验证,确认也会触发。

我的问题是我在哪里放置确认码?

我有(为简洁起见)验证

rules: {
    supplier: {
      required: true,
    },
    product: {
      required: true,
    }
  },
messages: {
  supplier: {
    required: "Please enter the supplier's name"
  },
  product: {
    required: "Please enter the name of the product"
  }
},

submitHandler: function(form){
    postForm();
}

现在效果很好

然后我在另一个脚本中有这个

$('#product').click(function() {
    if(confirm("Are you sure that the details are correct?")){
        return true;
    }else{
         return false;
    }
 });

这也有效,但在验证完成之前触发 - 我已经尝试将它插入到 submitHandler 中,并在其中的提交处理程序和几个不同的地方,但我知道我显然遗漏了一些东西 - 任何建议表示赞赏(我正在使用以下插件 - validate.min 确认和格式化)

4

1 回答 1

1

在 submitHandler 里面试试:

if(confirm("Are you sure that the details are correct?")){
        postForm();
    }else{
         return false;
    }
于 2012-10-21T00:40:53.740 回答