jQuery验证程序-在动态添加验证时无法调用未定义错误的方法“调用" [英] jQuery validator - Cannot call method 'call' of undefined error - while adding validation dynamically

查看:61
本文介绍了jQuery验证程序-在动态添加验证时无法调用未定义错误的方法“调用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,用于动态更新jQuery验证.在文档加载中,我创建验证.此代码用于动态更新电话号码验证.应用此验证后,当我在电话号码文本框中输入任何内容时,我无法调用未定义错误的方法调用".

This is my code to update the jQuery validation dynamically. In document load i create the validation. This code is used to update the phone number validation dynamically. After apply this validation, when i enter anything in phone number text box i get cannot call method 'call' of undefined error.

 $("#phone").rules("remove");

$("#phone")
  .rules(
  "add",
  {
    required:true,
    minlength:5,
    maxlength:20,
    phoneUS:true,
    messages:{
    required: "Enter company phone number",
    minlength:"Phone number should contain a minimum of 5  characters",
    maxlength:"Phone number should contain a maximum of 20  characters",
    phoneUS:"Enter valid phone number"
  }

  });

先谢谢了.该如何解决?

Thanks in advance. How to solve this?

推荐答案

存在四个潜在问题.

1)您缺少messages部分的右括号.

1) You're missing a closing brace for the messages section.

$("#phone").rules("add", {
    required: true,
    phoneUS: true,
    messages: {
        required: "Enter company phone number",
        phoneUS: "Enter valid phone number"
    } //<-- this was missing 
});

演示: http://jsfiddle.net/A8HQU/2

DEMO: http://jsfiddle.net/A8HQU/2

2)有一个已知错误,其中使用rules('add')方法破坏了插件和/或规则.绝对确保您包含的是 jQuery Validate版本1.11.1 或更高版本.

2) There is a known bug where adding messages using the rules('add') method breaks the plugin and/or rule. Make absolutely sure you are including jQuery Validate version 1.11.1 or better.

3)phoneUS规则要求包含 additional-methods.js文件.

3) The phoneUS rule requires the inclusion of the additional-methods.js file.

4)rules('add')方法必须在.validate()初始化函数之后 .

4) The rules('add') method must come after the .validate() initialization function.

注意:

您使用的是phoneUS规则,因此minlengthmaxlength完全多余,因为phoneUS规则已经在寻找精确的格式/长度.

You're using the phoneUS rule, so minlength and maxlength are totally superfluous since the phoneUS rule is already looking for a precise format/length.

这篇关于jQuery验证程序-在动态添加验证时无法调用未定义错误的方法“调用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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