標籤:text use class post user meta body desc title
使用表單標籤,與使用者互動
網站怎樣與使用者進行互動?答案是使用HTML表單(form)。表單是可以把瀏覽者輸入的資料傳送到伺服器端,這樣伺服器端程式就可以處理表單傳過來的資料。
文法:
<form method="傳送方式" action="伺服器檔案">
講解:
1.<form> :<form>標籤是成對出現的,以<form>開始,以</form>結束。
2.action :瀏覽者輸入的資料被傳送到的地方,比如一個PHP頁面(save.php)。
3.method : 資料傳送的方式(get/post)。
<form method="post" action="save.php"> <label for="username">使用者名稱:</label> <input type="text" name="username" /> <label for="pass">密碼:</label> <input type="password" name="pass" /></form>
注意:
1、所有表單控制項(文字框、文本域、按鈕、單選框、複選框等)都必須放在 <form></form> 標籤之間(否則使用者輸入的資訊可提交不到伺服器上哦!)。
2、method : post/get 的區別這一部分內容屬於後端程式員考慮的問題。
文本輸入框、密碼輸入框
當使用者要在表單中鍵入字母、數字等內容時,就會用到文本輸入框。文字框也可以轉化為密碼輸入框。
文法:
<form> <input type="text/password" name="名稱" value="文本" /></form>
1、type:
當type="text"時,輸入框為文本輸入框;
當type="password"時, 輸入框為密碼輸入框。
2、name:為文字框命名,以備背景程式ASP 、PHP使用。
3、value:為文本輸入框設定預設值。(一般起到提示作用)
舉例:
<form> 姓名: <input type="text" name="myName"> <br/> 密碼: <input type="password" name="pass"></form>
在瀏覽器中顯示的結果:
文本域,支援多行文本輸入
當使用者需要在表單中輸入大段文字時,需要用到文本輸入欄位。
文法:
<textarea rows="行數" cols="列數">文本</textarea>
1、<textarea>標籤是成對出現的,以<textarea>開始,以</textarea>結束。
2、cols :多行輸入欄位的列數。
3、rows :多行輸入欄位的行數。
4、在<textarea></textarea>標籤之間可以輸入預設值。
舉例:
<form method="post" action="save.php"> <label>聯絡我們</label> <textarea cols="50" rows="10" >在這裡輸入內容...</textarea></form>
注意:代碼中的<label>標籤在本章5-9中講解。
在瀏覽器中顯示結果:
一個例子:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>表單標籤</title>
</head>
<body>
<form method="post" action="save.php">
<label for="username">使用者名稱:</label>
<input type="text" name="username" id="username" value="" />
<label for="pass">密碼:</label>
<input type="password" name="pass" id="pass" value="" />
<input type="submit" value="確定" name="submit" />
<input type="reset" value="重設" name="reset" />
</form>
</body>
</html>
HTML與使用者的互動 表單