我的表单正在使用jquery验证。但是,验证不会触发。我确信这只是一个小错误..任何人?
这是小提琴链接http://jsfiddle.net/2L6xT/
这里是我的jquery验证码
$(document).ready(function () {
<!-- validation -->
$('#submitDetails').validate({
// 1. validation rules.
rules: {
firstName: {
required: true,
maxlength: 120
},
lastName:{
required: true,
maxlength: 120
},
custom1: {
required: true,
maxlength: 120
},
state: {
required: true
},
custom9: {
required: true
},
email: {
required: true,
email: true
}
},
// 2. Validation fail messages
messages: {
custom9: {
required: "You must agree to the terms of conditions in order to participate."
}
},
errorPlacement: function(error, element) {
if (element.attr("name") == "custom9" )
error.appendTo("#error_msg");
else
error.insertAfter(element);
}
});
///execute when submit button is clicked
$("#submit").click(function () {
});
});
答案 0 :(得分:7)
在你的html中,input元素没有名称,验证器框架使用name来应用规则
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="First name" />
所以还有id add name(如果没有在其他地方使用,则不需要id)
演示:Fiddle