<script src="https://lf6-cdn-tos.bytescm.com/obj/cdn-static-resource/tt_player/tt.player.js?v=20160723"></script>
HTML表單
HTML 表單用于搜集不同類型的用戶輸入。
<form> 元素
<form> 元素定義 HTML 表單:
語(yǔ)法:<form></form>
HTML 表單包含表單元素。
表單元素指的是不同類型的 input 元素、復(fù)選框、單選按鈕、提交按鈕等等。
<input> 元素有很多形態(tài),根據(jù)不同的 type 屬性。
1. 文本輸入
<input type="text"> 定義用于文本輸入的單行輸入字段
2、密碼框
<input type="password"> 定義單選按鈕。
密碼框是為了隱藏用戶密碼信息的輸入框,語(yǔ)法形式與文本框差不多,不同的是類型 為 password。
3、單選按鈕輸入
<input type="radio"> 定義單選按鈕。
單選按鈕是在表單中有多個(gè)選項(xiàng),且只能選一個(gè)的情況下使用。
注:checked表示默認(rèn)選中項(xiàng)。
如:<input type="radio" name="sex"checked> 男
<input type="radio" name="sex"> 女
表示默認(rèn)選中男項(xiàng)。
4、復(fù)選框(Checkboxes)
<input type="checkbox"> 定義了復(fù)選框。
復(fù)選框是可以選多個(gè)選項(xiàng)的選項(xiàng)框,與單選不同的是復(fù)選框可以選取多個(gè)選項(xiàng),而且也可以默認(rèn)幾個(gè)選項(xiàng)都處于選中狀態(tài)。
注:checked表示默認(rèn)選中項(xiàng)。
如:<input type="checkbox" checked>
5、<select> 元素(下拉列表)
下拉列表是可以選擇的列表,當(dāng)在列表中選擇要選的選項(xiàng)時(shí)使用,只能選其中一個(gè)選項(xiàng)(通過(guò)設(shè)置也可以選幾項(xiàng))。
語(yǔ)法:
<select>
<option>北京</option>
<option selected>上海</option>
</select>
注:selected 表示默認(rèn)選中項(xiàng)
6、<textarea> 元素(文本域)
<textarea> 元素定義多行輸入字段:
文本域是用在要輸入多行文本,填寫(xiě)大量的文字時(shí)用到。
單標(biāo)簽
常見(jiàn)的語(yǔ)句:
form:表單標(biāo)簽格式
作用:用來(lái)收集用戶輸入信息如:登入、注冊(cè)、搜索商品等
action:開(kāi)始網(wǎng)址
method:get和post等等
text (明文):用戶名格式
password :(密文)密碼
radio :?jiǎn)芜x框 性別格式 性別是單選,單選類型是radio,注意name要加上sex
checkbox:復(fù)選框
textarea:文本框
file:上傳文件
select:下拉選擇框
button:按鈕
reset:重置
submit:提交
詳解:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表單標(biāo)簽</title>
</head>
<body>
<form action="https://hao.360.com/" method="post">
<p>賬號(hào):<input type="text" /></p>
<p>密碼:<input type="password" /></p>
<p>
<input type="radio" name="sex" id="" />男
<input type="radio" name="sex" id="" />女
</p>
<p>
<input type="checkbox" name="" id="" value="" />linux
<input type="checkbox" name="" id="" value="" />mysql
<input type="checkbox" name="" id="" value="" />html
<input type="checkbox" name="" id="" value="" />python
</p>
<p>學(xué)歷
<select name="">
<option value="">請(qǐng)選擇學(xué)歷</option>
<option value="">小學(xué)</option>
<option value="">初中</option>
<option value="">高中</option>
<option value="">大學(xué)</option>
</select>
</p>
<p>自我介紹:<br />
<textarea name="" rows="10" cols="30"></textarea>
</p>
<input type="reset" value="重置"/>
<input type="submit" value="提交"/>
<input type="button" value="按鈕"/>
</form>
</body>
</html>
TML 表單用于收集不同類型的用戶輸入,它是一個(gè)包含表單元素的區(qū)域。
表單元素是允許用戶在表單中輸入內(nèi)容,比如:文本域(textarea)、下拉列表、單選框(radio-buttons)、復(fù)選框(checkboxes)等等。今天我們主要來(lái)說(shuō)說(shuō)文本域和密碼域這兩個(gè)部分,希望對(duì)大家學(xué)習(xí)有所幫助喲!
本文福利后臺(tái)回復(fù)【學(xué)習(xí)】即可獲得Python、HTML等編程學(xué)習(xí)資料
HTML 表單
表單使用表單標(biāo)簽 <form> 來(lái)設(shè)置:
<form>
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname">
</form>
HTML 表單 - 輸入元素
多數(shù)情況下被用到的表單標(biāo)簽是輸入標(biāo)簽(<input>)。輸入類型是由類型屬性(type)定義的。
如何在 HTML 頁(yè)面創(chuàng)建文本域?
用戶可以在文本域中寫(xiě)入文本,參考代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鳥(niǎo)教程(runoob.com)</title>
</head>
<body>
<form action="">
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname">
</form>
<p><b>注意:</b> 表單本身是不可見(jiàn)的。并且注意一個(gè)文本字段的默認(rèn)寬度是20個(gè)字符。</p>
</body>
</html>
運(yùn)行結(jié)果為
如何創(chuàng)建 HTML 的密碼域?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鳥(niǎo)教程(runoob.com)</title>
</head>
<body>
<form action="">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="password">
</form>
<p><b>注意:</b> 密碼字段中的字符是隱藏的(顯示為星號(hào)或圓圈)。</p>
</body>
</html>
運(yùn)行結(jié)果如下
戳了解更多免費(fèi)領(lǐng)取HTML試聽(tīng)課~
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。