JQuery验证框架
程序员文章站
2022-06-12 22:21:49
...
JS 验证框架的官方地址:
http://docs.jquery.com/Plugins/Validation#API_Documentation
在页面中加入JS和CSS样式
<link href="${ctx}/resources/js/validate/jquery.validate.css" type="text/css" rel="stylesheet" />
<script src="${ctx}/resources/js/jquery.js" type="text/javascript"></script>
<script src="${ctx}/resources/js/validate/jquery.validate.js" type="text/javascript"></script>
<script src="${ctx}/resources/js/validate/jquery.validate.messages.js" type="text/javascript"></script>
在page的onload方法里面加上:
$("#signupForm").validate({ rules: { firstname: "required", lastname: "required", username: { required: true, minlength: 2 }, password: { required: true, minlength: 5 }, confirm_password: { required: true, minlength: 5, equalTo: "#password" }, email: { required: true, email: true }, topic: { required: "#newsletter:checked", minlength: 2 }, agree: "required" }, messages: { firstname: "Please enter your firstname", lastname: "Please enter your lastname", username: { required: "Please enter a username", minlength: "Your username must consist of at least 2 characters" }, password: { required: "Please provide a password", minlength: "Your password must be at least 5 characters long" }, confirm_password: { required: "Please provide a password", minlength: "Your password must be at least 5 characters long", equalTo: "Please enter the same password as above" }, email: "Please enter a valid email address", agree: "Please accept our policy" } });
现成的例子放在附件:
上一篇: 口角炎早期有哪些常见症状
下一篇: ZK在ZUL页面使用HTML