時(shí)間:2023-07-26 14:36:02 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-07-26 14:36:02 來(lái)源:網(wǎng)站運(yùn)營(yíng)
HTML5創(chuàng)建表單(上):<form></form>
。表單的基本語(yǔ)法格式如下:1<form action="url" method="get|post" enctype="mime">2</form>
其中,action
指定處理提交表單的格式,它可以是一個(gè)URL
或者一個(gè)電子郵箱地址;method
指明提交表單的HTTP
方法。enctype
指明用來(lái)把表單提交給服務(wù)器時(shí)的互聯(lián)網(wǎng)網(wǎng)媒體形式。1<!doctype html> 2<html> 3<head> 4<meta charset="utf-8"> 5<title>表單的基本使用</title> 6</head> 7<body> 8 <form> 9 下面是輸入用戶(hù)登錄信息<br>10 用戶(hù)名稱(chēng)11 <input type="text" name="user" ><br>12 用戶(hù)密碼13 <input type="password" name="password" ><br>14 15 <input type="submit" value="登錄">16 17 <input type="reset" value="重置">18</form>19</body>20</html>
渲染出來(lái)的效果如下:text
1<input type="text" name="..." size="..." maxlength="..." value="...">
下面對(duì)這些屬性進(jìn)行一個(gè)簡(jiǎn)單的說(shuō)明,type="text"
定義單行文本輸入框,name
定義文本框的名稱(chēng),為了保證數(shù)據(jù)采集的準(zhǔn)確性,故而要定義一個(gè)獨(dú)一無(wú)二的名稱(chēng);size
屬性定義文本框的寬度,單位是單個(gè)字符寬度;maxlength
定義最多輸入的字符數(shù);value
屬性定義文本框的初始值。1<!doctype html> 2<html> 3<head> 4<meta charset="utf-8"> 5<title>表單的基本使用</title> 6</head> 7<body> 8 <form> 9 用戶(hù)名稱(chēng):<br>10 <input type="text" name="username" size="20" maxlength="15" ><br>11 用戶(hù)地址:<br>12 <input type="text" name="address" size="20" maxlength="15" ><br>13</form>14</body>15</html>
渲染結(jié)果如下:textarea
textarea
主要用來(lái)輸入比較長(zhǎng)的文本信息,代碼格式如下:1<textarea name="..." cols="..." rows="..." wrap="...">2</textarea>
主要新出現(xiàn)的屬性,cols
定義多行文本框的寬度,單位是單個(gè)字符寬度;rows
多行文本框的高度,單位是單個(gè)字符高度;wrap
屬性定義輸入內(nèi)容大于文本域是顯示的方式。1<!doctype html> 2<html> 3<head> 4<meta charset="utf-8"> 5<title>表單的基本使用</title> 6</head> 7<body> 8 <form> 9 你對(duì)本網(wǎng)站的建議是:<br>10 <textarea name="advice" cols="50" rows="5"></textarea>11 <br>12 <input type="submit" value="提交">13 </form>14</body>15</html>
渲染之后得結(jié)果:password
1<input type="password" name="..." size="..." maxlength="...">
前面有過(guò)類(lèi)似的例子,在此就不重復(fù)了。radio
1<input type="radio" name="..." value="...">
其中,type="radio"
定義單選按鈕;name
定義單選按鈕的名稱(chēng),單選按鈕都是以組為單位使用的,在同一組中的單選項(xiàng)都必須用同一名稱(chēng)。1<!doctype html> 2<html> 3<head> 4<meta charset="utf-8"> 5<title>表單的基本使用</title> 6</head> 7<body> 8 <form> 9 請(qǐng)選擇你感興趣的圖書(shū)類(lèi)型:<br> <!-- 單選按鈕radio-->10 <input type="radio" name="book" value="Book1">網(wǎng)站編程<br>11 <input type="radio" name="book" value="Book2">辦公軟件<br>12 <input type="radio" name="book" value="Book3">設(shè)計(jì)軟件<br>13 <input type="radio" name="book" value="Book4">網(wǎng)絡(luò)管理<br>14 <input type="radio" name="book" value="Book5" checked>黑客攻防<br>15 </form>16</body>17</html>
渲染結(jié)果如下:checkbox
1<input type="checkbox" name="..." value="...">
看如下一個(gè)例子:1<!doctype html> 2<html> 3<head> 4<meta charset="utf-8"> 5<title>表單的基本使用</title> 6</head> 7<body> 8 <form> 9 請(qǐng)選擇你感興趣的圖書(shū)類(lèi)型:<br> <!-- 復(fù)選框checkbox-->10 <input type="checkbox" name="book" value="Book1">網(wǎng)站編程<br>11 <input type="checkbox" name="book" value="Book2">辦公軟件<br>12 <input type="checkbox" name="book" value="Book3">設(shè)計(jì)軟件<br>13 <input type="checkbox" name="book" value="Book4">網(wǎng)絡(luò)管理<br>14 <input type="checkbox" name="book" value="Book5" checked>黑客攻防<br>15 </form>16</body>17</html>
渲染結(jié)果如下:<select>
1<select name="..." size="..." multiple>2 <option value="..." selected>3 ...4 </option>5 ...6</select>
看如下一個(gè)例子:1<!doctype html> 2<html> 3<head> 4<meta charset="utf-8"> 5<title>表單的基本使用</title> 6</head> 7<body> 8 <form> 9 請(qǐng)選擇你感興趣的圖書(shū)類(lèi)型:<br> <!-- 選擇列表標(biāo)記select-->10 <select name="fruit" size="3" multiple>11 <option value="BOOK1">網(wǎng)站編程</option>12 <option value="BOOK2">辦公軟件</option>13 <option value="BOOK3">設(shè)計(jì)軟件</option>14 <option value="BOOK4">網(wǎng)絡(luò)管理</option>15 <option value="BOOK5">黑客攻防</option>16 </select>17 <br/>18</body>19</html>
渲染結(jié)果如下:button
1<input type="button" name="..." value="..." onclick="...">
其中onclick
屬性表示單擊行為,也可以通過(guò)指定腳本函數(shù)(如JavaScript)來(lái)定義按鈕的行為,這個(gè)我們到JavaScript部分就會(huì)十分清楚了。submit
1<input type="submit" name="..." value="...">
這個(gè)前面也有相關(guān)例子,在此不再?gòu)?fù)述。reset
1<input type="reset" name="..." value="...">
這個(gè)前面也提到過(guò),不再重復(fù)。關(guān)鍵詞:創(chuàng)建
客戶(hù)&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
客戶(hù)&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。