我的表单正在使用 jquery 验证。但是,验证没有触发。我确定这只是某个地方的一个小错误……有人吗?
这是 fiddle 链接 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 () {
});
});
最佳答案
在您的 html 中,输入元素没有名称,验证器框架使用名称来应用规则
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="First name" />
所以连同 id 一起添加 name(如果没有在其他地方使用,则不需要 id)
演示:Fiddle
关于javascript - jquery 验证不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21224337/