使用live()进行验证并通过ajax()提交 [英] Using live() with validation and submitting via ajax()
本文介绍了使用live()进行验证并通过ajax()提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JQuery中有这个
I have this in JQuery:
$("form").validate({ rules: {
captcha: {
required: true,
remote: {
url: "gb_include/captcha.php",
type: "post"
},
}
},
messages: {
captcha: "Correct captcha is required."
}});
$("form").submit(function(){
if($(this).valid() == true){ /* submit via ajax */ }
但是我必须给我们.live()
,因为在$(document).ready()
之后加载了表单,我该怎么办?
But I have to us .live()
because the form is loaded after $(document).ready()
how can i do that ?
推荐答案
您可以创建一个自定义事件,以在加载表单后运行.
You can create a custom event to run after the form is loaded.
$(document).bind('bindForm', function (e) {
$("#form").validate({ rules: {
captcha: {
required: true,
remote: {
url: "gb_include/captcha.php",
type: "post"
},
}
},
messages: {
captcha: "Correct captcha is required."
}});
$("form").submit(function(){
if($(this).valid() == true){ /* submit via ajax */ }
});
});
在加载表单的代码之后添加此代码:
Add this after the code that loads the form:
$(document).trigger('bindForm');
这篇关于使用live()进行验证并通过ajax()提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文