我无法使用 jquery 验证简单的 HTML 表单。请帮忙。以下是我的代码。
请注意我对 jquery 很陌生,所以这可能是一个愚蠢的问题。任何帮助将不胜感激
<script type="text/javascript">
function validate(){
alert("1");
$("#form1").validate({
rules: {
name: "required",
age: "required",
id: "required",
},
messages: {
name: " Enter username",
age: " Enter age",
id: " Enter id",
},
submitHandler: function(form) {
alert('3');
form.submit();
}
});
};
</script>
<title>Spring MVC Form Handling</title>
</head>
<body>
<h2></h2>
<form method="POST" action="addStudent.do" id=form1>
<div id="form-content">
<fieldset>
<div class="fieldgroup">
<label for="name">First Name</label>
<input type="text" id="name">
</div>
<div class="fieldgroup">
<label for="age">Age</label>
<input type="text" id="age">
</div>
<div class="fieldgroup">
<label for="id">Id</label>
<input type="text" id="id">
</div>
<div class="fieldgroup">
<input type="submit" value="Register" id="submit" class="submit" onclick="validate()">
</div>
</fieldset>
</div>
</form>
</body>