下載位址:http://bassistance.de/jquery-plugins/jquery-plugin-validation/
在表單的 input element 加上一些 class,定義好這個欄位該有什麼樣的值。例如:required, email, url, etc. (查看完整列表)
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body> <script type="text/javascript" src="js/jquery-1.7.1.js" charset="utf-8"></script> <script type="text/javascript" src="js/jquery-validation-1.9.0/jquery.validate.min.js"></script> <script type="text/javascript" src="js/jquery-validation-1.9.0/localization/messages_tw.js"></script> <script type="text/javascript" charset="utf-8"> $(document).ready( function(){ $('#commentForm').validate(); }); </script> <form id="commentForm" class="cmxform" method="POST" action=""> <fieldset> <legend>A simple comment form with submit validation and default messages</legend> <p> <label for="cname">Name</label> <em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" /> </p> <p> <label for="cemail">E-Mail</label> <em>*</em><input id="cemail" name="email" size="25" class="required email" /> </p> <p> <label for="curl">URL</label> <em> </em><input id="curl" name="url" size="25" class="url" value="" /> </p> <p> <label for="ccomment">Your comment</label> <em>*</em><textarea id="ccomment" name="comment" cols="22" class="required"></textarea> </p> <p> <input class="submit" type="submit" value="Submit"/> </p> </fieldset> </form>資料來源:http://brooky.cc/2011/08/04/using-jquery-validation-plugin-for-form-validation/
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。