javascript 类型错误:$.validator.methods[method] 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20774885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:16:37  来源:igfitidea点击:

TypeError: $.validator.methods[method] is undefined

javascriptjqueryjquery-validate

提问by IndexOutOfDevelopersException

I have some problem but I can't figure it out, I have see some examples and I have read few posts about this method, but still nothing.

我有一些问题,但我想不通,我看过一些例子,我读过一些关于这种方法的帖子,但仍然没有。

I get error:

我得到错误:

TypeError: $.validator.methods[method] is undefined

And belove that is:

亲爱的,那就是:

result = $.validator.methods[method].call( this, val, element, rule.parameters )

That means that function doesn't have all parameters and that is what coused error.

这意味着该函数没有所有参数,这就是导致错误的原因。

  1. question: What is worng with validation?
  2. question: How to validate drop down list and radio buttons with jquery-validate lib?
  3. question: What would be the most elegant way to send data to some php script with method post.
  1. 问题:验证有什么用?
  2. 问题:如何使用 jquery-validate 库验证下拉列表和单选按钮?
  3. 问题:使用方法 post 将数据发送到某些 php 脚本的最优雅的方式是什么。

My JS code:

我的JS代码:

$("#userData").validate({
    errorContainer: "#errorbox",
    errorLabelContainer: "#errorbox ul",
    wrapper: "li",

    rules: {
        first_name:{
            require:true,
            minlength: 2,
        },
        last_name: {
            required:true,
            minlength: 2,
        },
        number_room: "required",
        email: {
            required:true,
            email:true,
        },
    },
    messages: {
        first_name:{
            required: "Please enter name!",
            minlength: "At least 3 characters is needed for name",
        },
        last_name:{
            required: "Please enter surname!",
            minlength: "At least 3 characters is needed for surname",
        },
        number_room: "Potrebno je izbrati sobo",
        email:{
            required: "Please enter email!",
            email: "The format of email is: [email protected]",
        }
    }

});

My html code:

我的html代码:

<form id="userData" name="userData" method="POST" action="">
  <fieldset>
    <div id="errorbox"><ul></ul></div>
    <table width="450px">
      <tr>
      </tr>
      <tr>
        <td valign="top"><label for="cfirst_name">Name*</label></td>
        <td valign="top"><input type="text" id="first_name" name="first_name" maxlength="50" size="30" class="required"/></td>
      </tr>
      <tr>
        <td valign="top"><label for="clast_name">Surname *</label></td>
        <td valign="top"><input type="text" id="last_name" name="last_name" maxlength="50" size="30" class="required"/></td>
      </tr>
      <tr>
        <td valign="top"><label for="cnumber_room">Room number*</label></td>        <td valign="top"><select name="number_room" id="number_room" class="required">
            <option selected value="0"> Not choosen</option>
            <option value="1"> 1  </option>
            <option value="2"> 2   </option>
            <option value="3">3  </option>
            <option value="4"> 4   </option>
            <option value="5"> 5  </option>
            <option value="6"> 6  </option>
            <option value="7"> 7 </option>
            <option value="8"> 8  </option>
            <option value="9"> 9   </option>
            <option value="10"> 10   </option>
            <option value="11"> 11   </option>
            <option value="12"> 12   </option>
            <option value="13"> 13  </option>
            <option value="14"> 14  </option>
          </select>
        </td>
      </tr>
      <tr>
        <td valign="top"><label for="cemail">Elektronski naslov *</label></td>             <td valign="top"><input type="text" id="email" name="email" maxlength="50"   
                                                                                                                   size="30" class="required" /></td>
      </tr>
      <tr>
        <td colspan="2" style="text-align: center"><input class="submit" type="submit" value="Sendi"></td>
      </tr>
    </table>
  </fieldset>
</form>

回答by charlietfl

You have a typo in first_name/required... missing d

你有一个错字first_name/required......失踪d

Change:

改变:

 first_name:{
        require:true,
        minlength: 2,
    },

To

   first_name:{
        required:true,
        minlength: 2,
    },