什么是表單?
HTML表單是一個(gè)包含表單元素的區(qū)域,用來收集用戶輸入的內(nèi)容并提交,使用標(biāo)簽<form>來設(shè)置。一個(gè)表單里通常包括如下標(biāo)簽:
text 定義用于文本輸入的單行輸入字段(默認(rèn)寬度為20個(gè)字符)
password 密碼框
checkbox 多選按鈕
radio 單選按鈕
file 上傳文件
date 日期
submit 提交
botton 普通按鈕
reset 重置按鈕
select 下拉選擇
textarea 多行文本
hidden 隱藏域
常用表單標(biāo)簽
1.文本框
通過<input type="text"> 標(biāo)簽來設(shè)定,當(dāng)用戶要在表單中鍵入用戶名、郵箱等少量?jī)?nèi)容時(shí),就會(huì)用到文本域。
姓名:<input type="text" placeholder="用戶名">
2.密碼框
通過<input type="password"> 標(biāo)簽來設(shè)定,當(dāng)用戶要在表單中鍵入密碼時(shí)用到
<input type="password">
3.單選框
通過標(biāo)簽<input type="radio"> 定義,例如下面選擇性別
<input type="radio" name="gender" value="man">男
<input type="radio" name="gender" value="woman">女
4.多選框
通過標(biāo)簽<input type="checkbox">定義,例如下面選擇愛好
<input type="checkbox" name="hobby" value="hobby1">dota
<input type="checkbox" name="hobby" value="hobby2">旅游
<input type="checkbox" name="hobby" value="hobby3">寵物
5.提交按鈕
通過標(biāo)簽定義,用來提交表單的內(nèi)容到<form>標(biāo)簽action屬性的指定地址,數(shù)據(jù)傳送的方式和目的地由<form>標(biāo)簽定義
<input type="submit">