国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

多種實例解析HTML表單form的使用方法_0

2020-03-24 18:07:53
字體:
供稿:網(wǎng)友
九個簡單實例為大家分析了HTML表單form的使用方法,供大家參考,具體內(nèi)容如下1 form表單標(biāo)簽網(wǎng)站怎樣與用戶進(jìn)行交互?答案是使用HTML表單(form)。表單是可以把瀏覽者輸入的數(shù)據(jù)傳送到服務(wù)器端,這樣服務(wù)器端程序就可以處理表單傳過來的數(shù)據(jù)。
語法:

form method= 傳送方式 action= 服務(wù)器文件 form : form 標(biāo)簽是成對出現(xiàn)的,以 form 開始,以 /form 結(jié)束。
action :瀏覽者輸入的數(shù)據(jù)被傳送到的地方,比如一個PHP頁面(save.php)。
method : 數(shù)據(jù)傳送的方式(get/post)。所有表單控件(文本框、文本域、按鈕、單選框、復(fù)選框等)都必須放在 form /form 標(biāo)簽之間(否則用戶輸入的信息可提交不到服務(wù)器上哦!)。
method:post/get的區(qū)別這一部分內(nèi)容屬于后端程序員考慮的問題。感興趣的小伙伴可以查看本小節(jié)的wiki,里面有詳細(xì)介紹。XML/HTML Code復(fù)制內(nèi)容到剪貼板
formmethod= post action= save.php labelfor= username 用戶名: /label inputtype= text name= username / labelfor= pass 密碼: /label inputtype= password name= pass / /form
2 input/text/password文本和密碼輸入框當(dāng)用戶要在表單中鍵入字母、數(shù)字等內(nèi)容時,就會用到文本輸入框。文本框也可以轉(zhuǎn)化為密碼輸入框。
語法:XML/HTML Code復(fù)制內(nèi)容到剪貼板
form inputtype= text/password name= 名稱 html' target='_blank'>value= 文本 / /form
當(dāng)type= text 時,輸入框為文本輸入框;
當(dāng)type= password 時, 輸入框為密碼輸入框。
name:為文本框命名,以備后臺程序ASP 、PHP使用。
value:為文本輸入框設(shè)置默認(rèn)值。(一般起到提示作用)測試代碼:XML/HTML Code復(fù)制內(nèi)容到剪貼板
head metahttp-equiv= Content-Type content= text/html;charset=utf-8 title 文本輸入框、密碼輸入框 /title /head body formmethod= post action= save.php 賬戶: inputtype= text name= myName / br br 密碼: inputtype= password name= pass / /form /body /html

3 textarea文本域,支持多行文本輸入當(dāng)用戶需要在表單中輸入大段文字時,需要用到文本輸入域。
語法:

textarea rows= 行數(shù) cols= 列數(shù) 文本默認(rèn)值 /textarea 1、 textarea 標(biāo)簽是成對出現(xiàn)的,以 textarea 開始,以 /textarea 結(jié)束。
2、cols :多行輸入域的列數(shù)。
3、rows :多行輸入域的行數(shù)。
4、在標(biāo)簽之間可以輸入默認(rèn)值。XML/HTML Code復(fù)制內(nèi)容到剪貼板
head metahttp-equiv= Content-Type content= text/html;charset=utf-8 title 文本域 /title /head body formaction= save.php method= post label 個人簡介: /label br textareacols= 40 rows= 10 在這里輸入內(nèi)容... /textarea br inputtype= submit value= 確定 name= submit / inputtype= reset value= 重置 name= reset / /form /body /html
4 radio/checkbox單選框和復(fù)選框在使用表單設(shè)計調(diào)查表時,為了減少用戶的操作,使用選擇框是一個好主意,html中有兩種選擇框,即單選框和復(fù)選框,兩者的區(qū)別是單選框中的選項用戶只能選擇一項,而復(fù)選框中用戶可以任意選擇多項,甚至全選。
語法:

input type= radio/checkbox value= 值 name= 名稱 checked= checked / 1.當(dāng) type= radio 時,控件為單選框
2.當(dāng) type= checkbox 時,控件為復(fù)選框
3.value:提交數(shù)據(jù)到服務(wù)器的值(后臺程序PHP使用)
4.name:為控件命名,以備后臺程序 ASP、PHP 使用
5.checked:當(dāng)設(shè)置 checked= checked 時,該選項被默認(rèn)選中
6.注意:同一組的單選按鈕,name 取值一定要一致,比如上面例子為同一個名稱 radioLove ,這樣同一組的單選按鈕才可以起到單選的作用。
XML/HTML Code復(fù)制內(nèi)容到剪貼板
head metahttp-equiv= Content-Type content= text/html;charset=utf-8 title 單選框、復(fù)選框 /title /head body formaction= save.php method= post 你喜歡旅游嗎?請選擇: br inputtype= radio name= radiolove value= like checked= checked 喜歡 inputtype= radio name= radiolove value= dislike 不喜歡 inputtype= radio name= radiolove value= unknown 無所謂 br br 你喜歡哪些運動? br inputtype= checkbox name= checkbox value= Run checked= checked Run inputtype= checkbox name= checkbox value= Basketball Basketball inputtype= checkbox name= checkbox value= FootBall FootBall inputtype= checkbox name= checkbox value= Fat checked= checked Fat /form /body /html

該演示代碼實現(xiàn)了一個單選框包含3個選項,和一個復(fù)選框包含4選項; 同一個選框的name值必須一致,否則不能實現(xiàn)單選和復(fù)選功能。在同一個選框中value值必須不同,否則傳遞到后臺數(shù)據(jù)有誤。5 select/option使用下拉列表框單選下拉列表在網(wǎng)頁中也常會用到,它可以有效的節(jié)省網(wǎng)頁空間。既可以單選、又可以多選。語法:

option value= name selected= selected Run /option Value為向服務(wù)器提交的值; 設(shè)置selected= selected 屬性,則該選項就被默認(rèn)選中。XML/HTML Code復(fù)制內(nèi)容到剪貼板
head metahttp-equiv= Content-Type content= text/html;charset=utf-8 title 下拉列表框 /title /head body formaction= save.php method= post label 愛好: /label select optionvalue= 看書 看書 /option optionvalue= 旅游 selected= selected 旅游 /option optionvalue= 運動 運動 /option optionvalue= 購物 購物 /option /select inputtype= submit name= submit value= submit inputtype= reset name= reset value= reset br br label 留言給我們: /label br textareacols= 40 rows= 5 在這里輸入留言... /textarea br inputtype= submit value= 點擊確認(rèn)提交留言 name= advise /form /body /html
6 select/multiple/option使用下拉框多選下拉列表也可以進(jìn)行多選操作,在標(biāo)簽中設(shè)置multiple= multiple 屬性,就可以實現(xiàn)多選功能,在 widows 操作系統(tǒng)下,進(jìn)行多選時按下Ctrl鍵同時進(jìn)行單擊(在 Mac下使用 Command +單擊),可以選擇多個選項。XML/HTML Code復(fù)制內(nèi)容到剪貼板
head metahttp-equiv= Content-Type content= text/html;charset=utf-8 title 使用下拉列表框進(jìn)行多選 /title /head body formaction= save.php method= post label 愛好: /label br selectmultiple= multipl optionvalue= 看書 看書 /option optionvalue= 旅游 旅游 /option optionvalue= 運動 運動 /option optionvalue= 購物 購物 /option /select br br label 留言給我們: /label br textareacols= 40 rows= 5 在這里輸入留言... /textarea br inputtype= submit value= 點擊確認(rèn)提交留言 name= advise /form /body /html
語法: input type= submit value= 提交 type:只有當(dāng)type值設(shè)置為submit時,按鈕才有提交作用
value:按鈕上顯示的文字XML/HTML Code復(fù)制內(nèi)容到剪貼板
head metahttp-equiv= Content-Type content= text/html;charset=utf-8 title 提交按鈕 /title /head body formmethod= post action= save.php labelfor= myName 姓名: /label inputtype= text value= name= myName / inputtype= submit value= 提交 name= submitBtn / /form /body /html
8 input/reset使用重置按鈕重置表單信息當(dāng)用戶需要重置表單信息到初始時的狀態(tài)時,比如用戶輸入 用戶名 后,發(fā)現(xiàn)書寫有誤,可以使用重置按鈕使輸入框恢復(fù)到初始狀態(tài)。只需要把type設(shè)置為 reset 就可以。
語法: input type= reset value= 重置 1type:只有當(dāng)type值設(shè)置為reset時,按鈕才有重置作用
value:按鈕上顯示的文字XML/HTML Code復(fù)制內(nèi)容到剪貼板
head metahttp-equiv= Content-Type content= text/html;charset=utf-8 title 重置按鈕 /title /head body formaction= save.php method= post label 愛好: /label select optionvalue= 看書 看書 /option optionvalue= 旅游 selected= selected 旅游 /option optionvalue= 運動 運動 /option optionvalue= 購物 購物 /option /select inputtype= submit value= 確定 / inputtype= reset value= 重置 / /form /body /html
9 表單中l(wèi)abel標(biāo)簽label標(biāo)簽不會向用戶呈現(xiàn)任何特殊效果,它的作用是為鼠標(biāo)用戶改進(jìn)了可用性。如果你在 label 標(biāo)簽內(nèi)點擊文本,就會觸發(fā)此控件。就是說,當(dāng)用戶單擊選中該label標(biāo)簽時,瀏覽器就會自動將焦點轉(zhuǎn)到和標(biāo)簽相關(guān)的表單控件上(就自動選中和該label標(biāo)簽相關(guān)連的表單控件上)。
語法: label for= 控件id名稱 注意:標(biāo)簽的 for 屬性中的值應(yīng)當(dāng)與相關(guān)控件的 id 屬性值一定要相同。XML/HTML Code復(fù)制內(nèi)容到剪貼板
head metahttp-equiv= Content-Type content= text/html;charset=utf-8 title form中的lable標(biāo)簽 /title /head body form labelfor= male 男 /label inputtype= radio name= gender id= male / br/ labelfor= female 女 /label inputtype= radio name= gender id= female / br/ labelfor= email 輸入你的郵箱地址 /label inputtype= email id= email placeholder= Enteremail br 你對什么運動感興趣: br labelfor= run 慢跑 /label inputtype= checkbox name= sports id= run br labelfor= climb 登山 /label inputtype= checkbox name= sports id= climb br labelfor= basketball 籃球 /label inputtype= checkbox name= sports id= basketball br /form /body /htmlhtml教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 长治县| 德保县| 彰化市| 噶尔县| 崇州市| 上虞市| 彰化市| 馆陶县| 诏安县| 且末县| 铜梁县| 南部县| 宣汉县| 武宁县| 濉溪县| 孝义市| 棋牌| 安仁县| 中超| 华宁县| 凌源市| 许昌市| 柳林县| 平顺县| 平陆县| 涡阳县| 三穗县| 沙河市| 台中市| 四子王旗| 明溪县| 孝感市| 惠州市| 长沙市| 六安市| 墨玉县| 进贤县| 大悟县| 漳州市| 盐亭县| 甘孜县|