JQuery表單驗證插件jQuery.validate.js
來源:程序員人生 發布時間:2013-10-10 12:54:53 閱讀次數:3006次
今天把 jquery.validate.js 下載下來,看了下它給的demo。現在來總結下筆記。
jquery.validate.js 官網下載:http://bassistance.de/jquery-plugins/jquery-plugin-validation/
在上面可以下載到它的例子程序和js腳本
說明:本人看了下例子程序,有什么不對的請大家指正。謝謝!
使用它驗證表單有2中方式:
1.使用它內部定義好的驗證(也就是錯誤提示它已經定義好了。不需要我們再定義,這種方便,簡單。但不靈活。)
2.自定義錯誤提示,這種可以自己定義錯誤提示。需要寫的代碼就相對較多了。
實例1、使用jquery驗證定義好的錯誤提示。
一。我們先建一個表單,什么驗證也沒有的一個表單。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="jquery_asp.net._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>jquery validate </title>
</head>
<body>
<form id="commentForm" method="get" action="">
<fieldset>
<legend>請輸入你的姓名,電子郵件和網址,以及你的評論</legend>
<p>
<label for="cname">姓名(必填,并2個字符)</label>
<input id="cname" name="name" />
<p>
<label for="cemail">電子郵件 (必填)</label>
<input id="cemail" name="email" />
</p>
<p>
<label for="curl">網址 (可選)</label>
<input id="curl" name="url"value="" />
</p>
<p>
<label for="ccomment">你的評論 (必填)</label>
<textarea id="ccomment" name="comment"></textarea>
</p>
<p>
<input type="submit" value="提交"/>
</p>
</fieldset>
</form>
</body>
</html>
2.添加驗證
現在我們來添加驗證。
1.引入jquery腳本
<script type="text/javascript" src="http://www.jyygyx.com/uploads/Common/jquery-1.3.2.min.js"></script>
<script src="http://www.jyygyx.com/uploads/Common/js/jquery.validate.js" type="text/javascript"></script>
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈