<script>
function submitAddStudent() {
$("#modalForm").validate({
rules: {
name: {
required: true,
letterswithspace: true
},
email: {
required: true,
email: true
},
phone: {
required: true,
minlength: 10,
maxlength: 10,
digits: true
}
},
messages: {
name: {
required: "Please enter a name.",
letterswithspace: "Please enter a valid name with letters and spaces only."
},
email: {
required: "Please enter an email address.",
email: "Please enter a valid email address."
},
phone: {
required: "Please enter a phone number.",
minlength: "Please enter a valid 10-digit phone number.",
maxlength: "Please enter a valid 10-digit phone number.",
digits: "Please enter a valid 10-digit phone number."
}
},
errorElement: "span",
errorClass: "help-block",
highlight: function(element, errorClass, validClass) {
$(element).closest(".form-group").addClass("has-error");
},
unhighlight: function(element, errorClass, validClass) {
$(element).closest(".form-group").removeClass("has-error");
}
});
}
</script>
完整的代码:https://jsfiddle.net/wxber8yp/1/包括HTML和脚本文件在上面的链接供您参考。
在模态弹出表单中,它没有验证表单字段,我不能添加学生(添加学生)按钮在模态弹出窗口中不起作用。我希望表单应该通过jquery验证进行验证,并且应该将数据添加到数据库中。
1条答案
按热度按时间mwg9r5ms1#
你的代码中几乎没有错误。
1.你忘了在你的html中包含validate js
1.你在modal上调用validate。它应该在form上。为此,我在form中添加了id作为myForm。
1.该按钮应具有提交类型
1.表单应该 Package 所有的元素和按钮