代碼如下:
<%@ page language="java" pageEncoding="gbk"%>
<html>
<head>
<title>jqueryValidateDemo</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript">
$(function() {
$("#login").validate({
rules:{
name:{
required:true
},
password:{
required:true,
minlength:4
}
},
messages:{
name:{
required:"此項為必填項"
},
password:{
required:"此項為必填項",
minlength:"密碼長度至少為4個字符"
}
}
})
});
</script>
</head>
<body>
<form action="" id="login" method="post">
<table align="center" border="1">
<tr>
<td>登錄名</td>
<td><input type="text" id="name" name="name"/></td>
</tr>
<tr>
<td>密碼</td>
<td><input type="password" id="password" name="password"/></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="注冊"/></td>
</tr>
</table>
</form>
</body>
</html>