jQuery验证插件,动态表单验证 [英] Jquery Validation Plugin, dynamic form validation
本文介绍了jQuery验证插件,动态表单验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 Jquery验证插件用于通过以下方式加载的表单Ajax(动态形式).我知道从Jquery 1.4开始,现在可以提交实时事件.现在的问题是,我想在验证动态表单后显示一条确认消息.我的代码如下:
I'm using the Jquery Validation Plugin to forms loaded via Ajax (dynamic forms). I know that as of Jquery 1.4, live events on submit is now possible. Now the problem is I want to show a confirm message after the dynamic form has been validated. My code looks like this:
$('.dynamicForm').live('submit',function(){
$(this).validate();
if($(this).valid()){
if(!confirm('Are you sure?'))
e.preventDefault();
}
});
它没有按预期工作.首先以某种方式显示确认信息,然后在第二次提交表单时,即验证发生的时间.有什么想法吗?
It's not working as expected. Somehow confirmation shows first, then at the second time I submit the form, that's the time the validation happens. Any ideas?
推荐答案
这似乎可以正常工作:
$('.dynamicForm').live('mouseover',function(){
$(this).validate({
submitHandler:function(form){
if(confirm("Are you sure?")){
form.submit();
}
}
});
});
这篇关于jQuery验证插件,动态表单验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文