我需要一些字段,具体取决于单击的按钮。但我所看到的行为并不是我所期望或希望的。当我单击其中一个按钮时,它会按照我的意愿设置必填字段,但是如果我单击另一个按钮,它不会由于某种原因重置它们。
代码如下。感谢您的任何帮助,您可以提供:
function makeAllRequired() {
$("#SomeForm").validate({
rules: {
StartDate: {
required: true,
date: true
},
Name: {
required: true
}
},
errorElement: "div"
});
}
function makeSomeRequired() {
$("#SomeForm").validate({
rules: {
StartDate: {
required: true,
date: true
}
},
errorElement: "div"
});
}
$(document).ready(function () {
$("#SomeButtonOne").click(function () {
makeAllRequired();
$("#SomeForm").attr("action", "/here/there");
$("#SomeForm").submit();
});
$("#SomeButtonTwo").click(function () {
makeSomeRequired();
$("#SomeForm").attr("action", "/here/elsewhere");
$("#SomeForm").submit();
});
});
在设置新的必填项目之前尝试重置表单:http://docs.jquery.com/Plugins/Validation/Validator/resetForm http://docs.jquery.com/Plugins/Validation/Validator/resetForm
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)