且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

每个多个字段集的jQuery验证,如何使用不同的事件触发每个节的验证

更新时间:2022-12-11 10:55:41

我不认为这是一个简单的解决方案,但是我在当前项目中做了类似的事情.

I don't think this is a trivial solution, but I have done something similar in my current project.

1)将事件绑定到每个下一个链接.在这种情况下,您将使用jquery验证插件的 element 方法手动验证字段集中的每个输入.

1) Bind an event to each next link. In the event, you are going to validate each input in the fieldset manually using the element method of the jquery validation plugin.

2)在事件中,获取当前字段集.您的插件可能可以为您跟踪此操作,但是我对此并不熟悉.

2) In the event, get the current fieldset. Your plugin can probably keep track of this for you, but I'm not familiar with it.

3)在字段集中搜索其所有输入,然后分别进行验证.

3) Search the fieldset for all of its inputs and validate them individually.

4)如果该字段集中的任何输入无效,请不要前进到下一页.

4) If any of the inputs in the fieldset are invalid, don't advance to the next page.

每当单击下一个链接时,以下代码段便会手动验证字段集中的非隐藏输入.它没有显示如何检索字段集和验证器,或者如果表单无效则如何停止前进到下一个字段集.您的表单插件可以帮助您解决此问题.从该示例中可以得到的是,您可以使用jquery验证插件手动验证字段集中的所有输入.

The following piece of code manually validates the non hidden inputs in a fieldset whenever the next link is clicked. It does not show how to retrieve the fieldset and validator or how to stop the progression to the next fieldset if the form is invalid. Your form plugin may be able to help with this. What you should get out of this example is that you can manually validate all the inputs in a fieldset using the jquery validation plugin.

$('.next').bind('click', function() {
 var inputs = myFieldset.find(':input:not(:hidden)');
 for (var i = 0; i < inputs.length; i++) {
   myValidator.element($(inputs[i]));
 }
});