gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 02:11:14 25 4
gpt4 key购买 nike

我遇到了一些问题,但我无法弄清楚,我已经看到了一些示例,并且我读了一些关于此方法的帖子,但仍然一无所获。

我收到错误:

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

最喜欢的是:

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

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

  1. 问题:什么是验证?
  2. 问题:如何使用 jquery-validate lib 验证下拉列表和单选按钮?
  3. 问题:使用 post 方法将数据发送到某些 php 脚本的最优雅的方式是什么。

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

最佳答案

您在first_name/required中有拼写错误...缺少d

更改:

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

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

关于javascript - TypeError : $. validator.methods[method] 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20774885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com