使用 jQuery validate 验证添加到 DOM 的表单
快速问题:我如何使用好的、旧的 jQuery Validate 来验证添加到页面加载后的 DOM(通过 Ajax)?
$("form#superForm").validate(options);
不起作用...
谢谢!
Quick question: How can I use good, old jQuery Validate to validate a form which gets added to the DOM (via Ajax) after the page has loaded?
$("form#superForm").validate(options);
doesn't work...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$("form#superForm").validate(options);
确实有效。只是您尝试在加载内容 (form#superForm
) 之前附加它。如果您希望它正常工作,则必须在加载后附加它。因此,例如:
$("form#superForm").validate(options);
does work. It's just that you're trying to attach it before the content (form#superForm
) is loaded.If you want it to work properly, you'll have to attach it after you've loaded it in. So, for example:
它将起作用,您只需在将表单添加到 DOM(位于 AJAX 调用的成功回调中)后调用它。我想当 DOM 中尚不存在表单时,您会在
document.ready
中调用它。例如:
It will work, you only have to call it once the form is added to the DOM which is in the success callback of your AJAX call. I suppose that you are calling it in
document.ready
when the form doesn't exist yet in the DOM.For example: