按钮点击时出发validate方法:
$("#btnQuery").click(function() {
$("form").validate(validate_settings_query);
});
$("form").validate(validate_settings_query);
});
validate_settings_query这个是validate的option参数,那么实现不同的校验逻辑,实际上就是构造不同的option参数即可:
$(document).ready(function() {
var _customer_query = {
rules: {
txtCustEmail: {
required: true,
email: true
}
}, //end rule
messages: {
txtCustEmail: {
required: "账号不能为空",
email: "请录入正确格式的Email地址"
}
}//end message
};
var _customer_submit = {
rules: {
txtCustAmount: {
required: true
}
}, //end rule
messages: {
txtCustAmount: {
required: "金额不能为空"
}
}//end message
};
var validate_settings_query = jQuery.extend({}, _default, _customer_query);
var validate_settings_submit = jQuery.extend({}, _default, _customer_submit);
$("#btnQuery").click(function() {
$("form").validate(validate_settings_query);
});
$("#btnSubmit").click(function() {
$("form").validate(validate_settings_submit);
});
});
var _customer_query = {
rules: {
txtCustEmail: {
required: true,
email: true
}
}, //end rule
messages: {
txtCustEmail: {
required: "账号不能为空",
email: "请录入正确格式的Email地址"
}
}//end message
};
var _customer_submit = {
rules: {
txtCustAmount: {
required: true
}
}, //end rule
messages: {
txtCustAmount: {
required: "金额不能为空"
}
}//end message
};
var validate_settings_query = jQuery.extend({}, _default, _customer_query);
var validate_settings_submit = jQuery.extend({}, _default, _customer_submit);
$("#btnQuery").click(function() {
$("form").validate(validate_settings_query);
});
$("#btnSubmit").click(function() {
$("form").validate(validate_settings_submit);
});
});