一、表單
##1.表單的作用
HTML 表單用于接收不同類(lèi)型的用戶(hù)輸入,用戶(hù)提交表單時(shí)向服務(wù)器傳輸數(shù)據(jù),從而實(shí)現(xiàn)用戶(hù)與Web服務(wù)器的交互广匙。
二、簡(jiǎn)單使用
首先需要form包裹整個(gè)需要提交的input數(shù)據(jù)
<form action="/login.html" method="post">
<div class="usernmae">
<label for="usernmae">用戶(hù)名:</label>
<input id="username" type="text" name="username">
</div>
<div class="password">
<label for="password">密碼:</label>
<input type="text" id="password" name="password">
</div>
<div class="submit">
<button type="button">提交</button>
<input type="reset" value="重置">
</div>
</form>
需要注意的是 一定要在form的包括當(dāng)中 如果不是就無(wú)法提交數(shù)據(jù)到后臺(tái)恼策。
login.html
action
是屬于往哪個(gè)地方提交數(shù)據(jù)
method
提交時(shí)用于什么方法 默認(rèn)不填就是get
name
屬于整個(gè)提交當(dāng)中的唯一標(biāo)識(shí)
<label for="usernmae">用戶(hù)名:</label>
在左邊提示for中的變量名一定是和input中的id是一致的鸦致,還有一個(gè)就是點(diǎn)擊用戶(hù)名就會(huì)自動(dòng)跳轉(zhuǎn)到input框當(dāng)中
<button type="button">
是提交整個(gè)form中的input數(shù)據(jù)
<input type="reset" value="重置">
重置功能,屬于批量清空刪除input框中的數(shù)據(jù)戏蔑,回到原始狀態(tài)
當(dāng)選和復(fù)選框
譬如<input type="checkbox" name="hobby" value="read">讀書(shū)
checkbox
就是復(fù)選框 可選多個(gè)
value
是當(dāng)前input框中的值
<input type="radio" name="hobby" value="read">
radio是當(dāng)選框 如果是多個(gè)只能選擇一個(gè)蹋凝。
文件
<input type="file" name="myfiel" accept="image/png">
type=file是文件類(lèi)型的
accept
限制是什么后綴名
下拉選擇框
譬如
<select class= name="city">
<option value="beijing">北京</option>
<option value="guangzhou" selected="">廣州</option>
<option value="hangzhou">杭州</option>
</select>
下拉選擇框不同input框 name只需一個(gè)包裹在select標(biāo)簽中,selected是默認(rèn)選中項(xiàng)
文本框
<textarea name="article" id="" cols="30" rows="10"></textarea>
cols
列
rows
行