客户端验证不适用于dom操纵元素? [英] Client validation does not work on dom manipulated elements?

查看:115
本文介绍了客户端验证不适用于dom操纵元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有select元素和input元素的简单表单。根据select元素中的值,我可能需要或者可能不需要验证输入元素。

I have a simple form with a select element and an input element. Depending on the value in the select element i might or might not need the input element validated.

我做的是,我在'data-val'属性上设置了输入元素为'true'或'false',具体取决于select元素中选择的内容。这部分正在运行 - 我可以检查firebug中属性的值,它确实会根据计划进行更改。

What i did is, i set the 'data-val' attribute on the input element to either 'true' or 'false' depending on what is selected in the select element. This part is working - i can inspect the value of the attribute in firebug and it does change according to the plan.

现在,为了让jquery不引人注意的验证到注意我打电话给dom的变化

Now, in order to have the jquery unobtrusive validation to notice the change in the dom i call

$.validator.unobtrusive.parse(document)

我尝试传递表单或元素,所以我想传递文档实际上只是我最近的尝试。我尝试传递表单的jquery对象,以及dom-form元素。我还尝试仅验证调用的输入元素

I tried passing the form or the element, so i guess passing the document is actually just my latest attempt. I tried passing the jquery object of the form, as well as the dom-form element. I also tried validating only the input element calling

$.validator.unobtrusive.parseElement(myElement)

再次,我尝试使用jquery对象以及'nekid dom元素'。

Again, i tried with the jquery object as well as the 'nekid dom element'.

我在这里缺少什么?

推荐答案

是的,parse元素不能动态工作。试试这个 - 这对我和其他几个人都有效....

yeah, parse element does not work dynamically. Try this -it worked for me and a fair few others....

http://xhalent.wordpress.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/

这篇关于客户端验证不适用于dom操纵元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆