【发布时间】:2015-04-30 12:51:27
【问题描述】:
我的问题是 jquery validate 不起作用。firebug 也没有显示任何类型的错误。下面是 jquery:
$("#AlertForm").validate({
rules: {
alertcategory: "required",
alertsubcategory: "required",
alertcity: "required",
alertemail: { required: true, email: true },
alertphone: { required: true, number: true, maxlength: 10 }
},
// Specify the validation error messages
messages: {
alertcategory: "Please Select one category from dropdown",
alertsubcategory: "Please select subcategory based on category above.",
alertcity: "Please select one city from dropdown",
alertcity: "Please enter your email id",
alertphone: "Please enter your phone number"
},
});
我已将此代码放入文档准备功能中。我还为表单的每个元素提供了名称,类,id,但仍然没有成功。另外,我的表单内部包含各种 div 标签。请帮助。
我的表单代码:
<div class="content_part_two">
<form method = "post" class ="AlertForm" id="AlertForm" name="AlertForm" action="#">
<div class="container">
<div class="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2 col-sm-8 col-sm-offset-2 col-xs-10 col-xs-offset-1 content_part ">
<img src="<?php echo URL;?>img/alert.png" />
<h3>Create Free Alert</h3>
<div class="full_part sell_part">
<div class="half_part">
<select name="FreeAlertSelect" class="selectpiker" id ="FreeAlertSelect" >
<option selected="selected">I Want to Sell-Remind Me</option>
</select>
</div>
</div>
<div class="full_part">
<div class="half_part pull-left">
<select name="AlertSelectCategory" class="selectpiker" id = "AlertSelectCategory" >
<option value="null">Category</option>
<option>Slow</option>
<option >Medium</option>
<option>Fast</option>
<option>Faster</option>
</select>
</div>
<div class="half_part pull-right">
<select name="AlertSelectSubcategory" class="selectpiker" id = "AlertSelectSubcategory" >
<option value="null">Sub Category</option>
<option>Slow</option>
<option>Medium</option>
<option>Fast</option>
<option>Faster</option>
</select>
</div>
</div>
<div class="full_part">
<div class="half_part pull-left col-md-offset-3">
<select name="AlertCity" class="selectpiker" id="AlertCity" >
<option value="null">City</option>
<option>Slow</option>
<option>Medium</option>
<option>Fast</option>
<option>Faster</option>
</select>
</div>
</div>
<div class="full_part">
<div class="half_part pull-left">
<input type="text" placeholder="E-mail" id="AlertEmail" name="AlertEmail"/>
</div>
<div class="half_part pull-right">
<input type="text" placeholder="Phone" id="AlertPhone" name="AlertPhone"/><span id="erralertmsg"></span>
</div>
</div>
<div class="full_part sell_part">
<div class="half_part">
<input type="submit" value="submit" name = "FreeAlertSubmit" id="FreeAlertSubmit" />
</div>
</div>
</div>
</div>
</form>
</div>
【问题讨论】:
-
请添加您的表单代码。
-
你有两个
alertcity键和一个额外的逗号。我猜第二个应该是alertemail? -
我做了你提到的。仍然没有错误,并且验证插件仍然没有正常运行..
-
您的 HTML 字段
name属性中没有一个实际上与您在.validate()方法中使用的任何名称匹配。您希望插件如何找到这些字段?否则,它将起作用:jsfiddle.net/ff7qzLu8