jQuery验证尚未创建的元素 [英] jquery validate on elements not yet created
问题描述
我想知道是否有可能让jQuery Validator插件验证最初设置规则时dom中尚不存在的元素.
I'm wondering if it's possible to have the jQuery Validator plugin validate elements that don't yet exist in the dom when the rules are initially setup.
调用.Rules("add",therules)方法仅将规则附加到dom中当前存在的元素.如果我要创建一些.验证不会触发.有什么想法吗?
Calling the .Rules("add", therules) method only attaches the rules to elements that currently exist in the dom. If I were to create some. The validation doesn't fire. Any thoughts?
我正在使用的验证程序的主页: http://bassistance.de/jquery-plugins/jquery-plugin-validation/
Homepage of the validator I am using: http://bassistance.de/jquery-plugins/jquery-plugin-validation/
通过 http://ejohn.org/blog/javascript-创建新元素微型模板/
基本上有一个ajax调用,服务器返回一堆json(ajaj?),此json由resig的模板引擎提供.示例模板如下所示:
Basically there's an ajax call and the server returns a bunch of json (ajaj?), this json is fed through with the resig's templating engine. An example template looks like so:
<script type="text/html" id="ProductsTemplateEdit">
<td>
<input type="hidden" value="<#= item.ID #>" id="Edit.ID" name="Edit.ID" />
<input type="text" value="<#= item.Price#>" id="Edit.Price" name="Edit.Price" />
</td>
</script>
这些值显然是通过传入的json填充的.
The values are obviously filled in via the json that is passed in.
我还应该提到我正在使用xval验证框架,该框架基本上会自动为我生成jquery验证规则:
I should also mention that I am using the xval validation framework, which basically automatically generates the jquery validate rules for me: http://blog.codeville.net/2009/01/10/xval-a-validation-framework-for-aspnet-mvc/
推荐答案
好的,尝试两个.什么是动态添加元素?您不能只将.Rules("add",)放在相同的代码中吗?
Okay, try two. What is adding your elements dynamically? Can't you just place the .Rules("add", ) to the same code?
这篇关于jQuery验证尚未创建的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!