TypeError:$ .validator.methods [method]未定义

时间:2013-12-25 16:46:04

标签: javascript jquery jquery-validate

我有一些问题,但我无法弄明白,我看到了一些例子,我看过几篇关于这种方法的帖子,但仍然没有。

我收到错误:

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

然后就是:

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

这意味着函数没有所有参数,这就是错误。

  1. 问题:验证的内容是什么?
  2. 问题:如何使用jquery-validate lib验证下拉列表和单选按钮?
  3. 问题:使用方法发布将数据发送到某些php脚本的最优雅方式是什么。
  4. 我的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: john.deer@gmail.com",
            }
        }
    
    });
    

    我的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>
    

1 个答案:

答案 0 :(得分:9)

first_name/required ...错过了d

变化:

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

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