【问题标题】:jQuery unobstrusive validation returning valid when it is notjQuery 不显眼的验证在无效时返回有效
【发布时间】:2011-08-05 11:48:56
【问题描述】:

我有一个需要输入的表单,但 jQuery 说该字段有效时无效。这很奇怪,因为从 HTML 看来它是有价值的。

这是 Chrome 控制台中三个命令的输出,文本框完全为空:

// First I ensure that the selector is correct. But I can see that it has value, 
// when it is actually empty.
$('#form_0 input[name=Name]')[0].outerHTML

"<input data-val="true" data-val-length="The field Customer name must be a string with a minimum length of 3 and a maximum length of 20." data-val-length-max="20" data-val-length-min="3" data-val-required="The Customer name field is required." id="Name" name="Name" type="text" value="             Customer 0         " class="valid">"

// jQuery confirms that the field is empty
$('#form_0 input[name=Name]').val()

""

// but jQuery say that the control is valid :?
$('#form_0 input[name=Name]').valid()

1

表单和输入是用 jQuery 动态创建的。

可能是什么问题?

谢谢。

【问题讨论】:

  • 你能提供一个网站的 URL 来测试吗?
  • 很遗憾没有,我会尝试做一个概念证明,我会把它放在这里。

标签: javascript jquery jquery-validate unobtrusive-validation


【解决方案1】:
$.validator.unobtrusive.parse('#form_0');

当我动态添加输入时,我不知道我必须再次调用它。我想我必须阅读更多的文档和更少的例子:P

【讨论】:

    猜你喜欢
    • 2019-07-24
    • 2017-02-16
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    相关资源
    最近更新 更多