我正在尝试使用 jquery 验证我的表单,但我无法让它工作。当我单击提交时,它不会显示任何错误消息。
你能告诉我问题出在哪里吗?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="validation.js"></script>
<script>
$(document).ready(function() {
// validate signup form on keyup and submit
var validator = $("#signupform").validate({
rules: {
fname: "required",
lname: "required",
username: {
required: true,
minlength: 2,
remote: "<? echo base_url();?>mycontroller/function" }
},
messages: {
fname: "Enter your firstname",
lname: "Enter your lastname",
username: {
required: "Enter a username",
minlength: jQuery.format("Enter at least {0} characters"),
remote: jQuery.format("{0} is already in use")
},
},
});
</script>
我的表格
<!--I am trying to show all the error message here -->
<form id="signupform" autocomplete="off" method="get" action="">
FName:
<input id="fname" name="fname" type="text" value="" />
Lname:
<input id="lname" name="lname" type="text" value="" />
username:
<input id="username" name="username" type="text" value="" /> <br>
<input id="signupsubmit" name="signup" type="submit" value="Signup" />
</form>