jquery.validate.unobtrusive 不适用于动态注入元素 [英] jquery.validate.unobtrusive not working with dynamic injected elements
问题描述
我正在使用 ASP.Net MVC3
,使用客户端验证的更简单方法是启用 jquery.validate.unobtrusive
.对于来自服务器的东西,一切正常.
I am working with ASP.Net MVC3
, the easier way to use the client validation would be enabling the jquery.validate.unobtrusive
. Everything works fine, for stuff that's right from server.
但是当我尝试用 javascript 注入一些新的输入"时,我知道我需要调用 $.validator.unobtrusive.parse()
来重新绑定验证.但是,所有这些动态注入的字段都不起作用.
But when I try to inject some new 'inputs' with javascript, and I knew that I need to call $.validator.unobtrusive.parse()
to rebind the validations. But still, all those dynamic injected fields are not functioning.
更糟糕的是,我尝试使用 jquery.validate
手动绑定,但它也不起作用.有什么想法吗?
Even worse, I try to manually bind using jquery.validate
and it is not working either. Any thoughts?
推荐答案
我为 jquery.validate.unobtrusive 库创建了一个扩展,它针对我的情况解决了这个问题 - 它可能很有趣.
I've created an extension for the jquery.validate.unobtrusive library that solved this problem for my situation - it might be of interest.
http://xhalent.wordpress.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/
这篇关于jquery.validate.unobtrusive 不适用于动态注入元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!