重置必填字段 - jQuery [英] Reset required fields - jQuery
问题描述
根据点击的按钮,我需要一些字段。我所看到的行为并不是我所期望的,也不是我想要的。当我单击其中一个按钮时,它会按照我的意愿设置所需的字段,但如果我单击另一个按钮,则由于某种原因它不会重置它们。
I have some fields that I'm requiring depending on which button is clicked. The behavior I'm seeing though is not what I would expect nor desire. When I click one of the buttons, it sets the required fields as I'd like, but then if I click another button, it doesn't reset them for some reason.
代码如下。感谢您提供的任何帮助:
Code is below. Thanks for any help you can provide:
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();
});
});
推荐答案
尝试重新设置表单,然后再设置新的必需项目:< a href =http://docs.jquery.com/Plugins/Validation/Validator/resetForm =nofollow> http://docs.jquery.com/Plugins/Validation/Validator/resetForm
Try reseting the form before setting new required items: http://docs.jquery.com/Plugins/Validation/Validator/resetForm
这篇关于重置必填字段 - jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!