1. 程式人生 > >jquery的form外掛的使用

jquery的form外掛的使用

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文件</title>
<script src="jquery.min.js"></script>
<script src="jquery.form.js"></script>
<script type="text/javascript">          
   $(document).ready(function() {  
     var options={
	     target:"#output1",
		 success:function(reponseText,statusText){alert(reponseText);alert(statusText);},
		 beforeSubmit:function(formData){
		     for(var i=0;i<formData.length;i++)
			 {
			    if(!formData[i].value)
				{
				   alert("不能為空!");
				   return false;
				}
			 }
			 return true;
		 },
		 clearForm:true	
	  };
      $("#myForm").ajaxForm(options);   
   });   
</script>
</head>

<body>
 <h3> form外掛的使用--ajaxForm(). </h3>
	<form id="myForm" action="form3.aspx" method="get"> 
	    名稱: <input type="text" name="name" /> <br/>
		密碼: <input type="text" name="pwd" /><br/> 	  
	    <input type="submit" id="test" value="提交" /> <br/>
	    <div id="output1"></div>
	</form>
</body>
</html>

伺服器檔案:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System.Data" %>
<%
	Response.CacheControl = "no-cache";
	Response.AddHeader("Pragma","no-cache");
	Response.Write("User:" + Request["name"] + " Password:" + Request["pwd"]);
%>