我写了一个带有一些计算的小表格。现在计算是使用按钮单击事件完成的。
$('a#check_var').click(function() {
// the below call the form validation
$("#bet_cal_form").valid();
<- My code here ->
});
现在一切正常,问题是我不希望我的代码执行,除非表单验证没有错误。目前我收到错误消息,但我的代码也被执行。
我写了一个带有一些计算的小表格。现在计算是使用按钮单击事件完成的。
$('a#check_var').click(function() {
// the below call the form validation
$("#bet_cal_form").valid();
<- My code here ->
});
现在一切正常,问题是我不希望我的代码执行,除非表单验证没有错误。目前我收到错误消息,但我的代码也被执行。
当然,使用if
声明。
if ($("#bet_cal_form").valid()) {
// Stuff that should only be done if form is valid
}
您需要 if 并取消链接,并且由于所有 ID 都必须是唯一的,因此您不需要选择器中的 a
$(function() {
$("#check_var").on("click",function(e) {
e.preventDefault();
// the below call the form validation
if($("#bet_cal_form").valid()) {
<- My code here ->
}
});
});