一、如何使用
引入js文件
<script src="jquery.js"></script><script src="jquery.validate-1.13.1.js"></script>
編寫html頁面,這里僅以用戶名、密碼為例
<body> <form id="demoForm"> <fieldset> <legend>用戶登錄</legend> <p> <label for="username">用戶名</label> <input type="text" id="username" name="username"> </p> <p> <label for="password">密碼</label> <input type="text" id="password" name="password"> </p> </fieldset> </form></body>
編寫script腳
$(document).ready(function(){ $("#demoForm").validate({ rules:{ username:{ required:true,// 是否必填 minlength:2, // 最小長度 maxlength:10 // 最大長度 }, password:{ required:true, minlength:2, maxlength:16 } } });});二、測試

如果大家還想深入學習,可以點擊兩個精彩的專題:jquery表單驗證大全 JavaScript表單驗證大全
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答