如何在 ajax 请求返回的渲染表单上使用 jquery.validete
我在使用 jquery 验证插件时遇到一个小问题。
它与正常页面加载期间呈现的静态表单完美配合。 我用于验证的代码看起来像这样
$('#form_name).validate({ (...) and other stuff
问题是当我使用 ajax 请求创建具有相同 ID 的弹出表单时,它将无法工作。
我找不到这个问题的正确答案,所以我来到这里。我想 $().live 方法可能很有用,但我不知道如何在没有事件(如“点击”、“提交”等)时使用它。
哦,并防止页面出现其他问题加载新的 ajax 表单的位置与呈现静态表单的页面不同,因此同一页面上的两个相同表单不会发生冲突。
I have a slight problem with usage of jquery validation plugin.
It works perfectly with static forms rendered during normal pageload.
The code I use for validation looks something likie this
$('#form_name).validate({ (...) and other stuff
The problem is when I use ajax request to create popup form with the same ID it won't work.
I couldn't find proper answer form this issue so I came here. I guess the $().live method could be usefull but I have no idea how to use it on no event like "click", "submit" etc..
Ow and to prevent other questions the page where new ajax form is loaded is located somwhere else than the page where the static form is rendered so there is no conflicts of two identical forms on the same page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前遇到过这个问题。新添加的 ajax 内容可能需要重新初始化触发器。您可以采取多种方法。以下只是其中之一。
将 javasciprt 绑定触发器放在一个函数中,并在 ajax 请求后调用它。
I have come across this problem before. Newly added ajax content may need the triggers reinitialising. There are several approaches you can take. Below is just one of them.
put the javasciprt bind triggers inside a function and call it after the ajax request.