提到<input type="image" />,說起來有些慚愧。之前的工作基本每周都要制作兩到三個注冊用戶的網頁。其中就用它提交表單。
那個時候我想當然的以為這是用js操作,才把表單數據提交的。直到前幾天同事問到了這個問題,我還以為用js提交表單,為此還打了一個
賭,雖然賭注很小,不用想結果我輸了。今天對它做個總結:
code:
<html lang="zh"> <head> <meta charset="UTF-8"> <title>test</title> </head> <style> .sbuImage{ background:url("http://www.58guakao.com/images/user/reg/reg-btn.gif") repeat scroll 0 0 rgba(0, 0, 0, 0); width:207px; height:34px; } </style> <body> <form method="POST" action="http://passport.cnblogs.com/login.aspx?test=testval"> <input type="text" name="uname" value="張三" /></br></br> <input type="pwd" name="pwd" value="123" /></br></br> <input class="sbuImage" type="image" value="type是image的按鈕提交表單" /></br></br> <input class="sbuImage" type="submit" value="type是submit的按鈕提交表單" /> </form> </body> </html>
一.input type="image" 與 type="submit"的區別(下文簡寫image和submit)
1.這兩者都可以響應請求;
2.不同之處是當 method="GET" 時,當鼠標點擊image時,除了能正常請求URL,還能把鼠標點擊圖片時的焦點坐標(注意:
這個焦點坐標是相對於點擊的圖片說的)作為參數出現在url里,以上面的例子來說,url是:
http://passport.cnblogs.com/login.aspx?uname=%D5%C5%C8%FD&pwd=123&x=168&y=21
url少了一個參數test=testval,下面會提到。
二.簡單說一下Form表單里POST請求與GET請求的區別
請求區別:
1.最顯然的區別是GET是從服務器獲取數據,服務器需要的數據會出現在url里;
2.POST是將數據傳給服務器;
參數傳遞不同:
1.GET請求時,action的url的參數會丟掉,就像上面的url少了test=testval,它只會把form表單里的參數傳在url里;
2.POST請求時,action的url的參數不會丟掉,同時也會把form表單里的參數傳到服務器;
安全性:
1.GET請求時,表單里的數據都會顯示在url里,相對POST請求不安全;
2.POST請求時,表單里的數據不會那樣明顯顯示在客戶端;
數據量:
GET請求傳遞數據量要小於POST請求很多。具體待測。
下面這個鏈接要詳細,可參考:
http://blog.sina.com.cn/s/blog_7ffb8dd501013kdm.html