html5表單及新增的改良元素詳解
發(fā)布時(shí)間:2016-06-07 09:01:39 作者:佚名
我要評(píng)論
下面小編就為大家?guī)?lái)一篇html5表單及新增的改良元素詳解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <!--表單內(nèi)元素的form屬性:為元素指定一個(gè)form屬性,屬性值為該表單的id-->
- <form id="testform">
- <input type="submit" />
- </form>
- <textarea form="testform"></textarea> <br /><hr />
- <!--表單內(nèi)元素的formaction屬性:可以提交到不同頁(yè)面-->
- <form id="form1" action="test.aspx">
- <input type="submit" name="s1" value="內(nèi)部提交到test2" formaction="test2.aspx" />
- <input type="submit" />
- </form>
- <!--formmethod:可以為每個(gè)表單元素指定不同的提交方法-->
- <form id="form2" action="test.aspx">
- name:<input type="text" name="name" /><br />
- <input type="submit" value="post方式提交" formmethod="post"/>
- <input type="submit" value="get方式提交" formmethod="get"/>
- </form><br/><hr />
- <!--formenctype:可以指定不同的編碼方式-->
- <form action="test2.aspx" method="post">
- <input type="text" name="name" id="name" value="test" />
- 文件:<input type="file" name="files" />
- <input type="submit" value="上傳" formaction="test.aspx" formenctype="multipart/form-data"/>
- <input type="submit" value="提交" />
- </form><br /><hr />
- <!--formtarget:提交后再何處打開(kāi)頁(yè)面-->
- <form action="test.aspx">
- <input type="submit" name="s1" value="s1本頁(yè)打開(kāi)" formaction="test2.aspx" formtarget="_self"/>提交到test2
- <input type="submit" name="s" value="s新頁(yè)打開(kāi)" formaction="test.aspx" formtarget="_blank"/>提交到test
- </form><hr />
- <!--autofocus:自動(dòng)獲得光標(biāo)焦點(diǎn)-->
- <input type="text" autofocus /><br />
- <!--control:通過(guò)該屬性來(lái)訪問(wèn)該表單元素-->
- <form >
- <label id="label">
- 郵編:<input id="txtzip" maxlength="6" /><small>請(qǐng)輸入6位數(shù)字</small>
- </label>
- <input type="button" value="設(shè)置默認(rèn)值" onclick="setValue()" />
- </form>
- <!--placeholder:未輸入狀態(tài)的輸入提示-->
- <input type="text" placeholder="請(qǐng)輸入內(nèi)容" /><br />
- <!--list:單行文本框的list屬性,屬性值為datalist的id。 autocomplete:自動(dòng)完成-->
- list屬性:<input type="text" list="mylist" autocomplete="on"/>
- <datalist id="mylist" >
- <option value="第一">第一</option>
- <option value="第二">第二</option>
- <option value="第三">三</option>
- </datalist><br />
- <!--pattern:設(shè)置正則表達(dá)式驗(yàn)證-->
- <form>
- 輸入一個(gè)字母與三個(gè)大寫(xiě)字母:<input type="text" pattern="[0-9][A-Z]{3}" required=""/>
- <input type="submit" />
- </form><br />
- <!--indeterminate:說(shuō)明復(fù)選框處于尚未明確是否選取狀態(tài)-->
- <input type="checkbox" indeterminate id="cb" />indeterminate<br />
- <!--image的height和width設(shè)置圖片高寬-->
- 設(shè)置圖片寬高:<input type="image" src="img/webp.jpg" alt="編輯" width="23" height="23" /><br />
- <!--textarea:maxlength和wrap屬性:hard換行也要指定cols,soft不換行-->
- <form action="test.aspx" method="post">
- <textarea name="name" maxlength="10" rows="5" cols="5" wrap="hard"></textarea>
- <input type="submit" value="提交" />
- </form><br />
- <!--url類(lèi)型:只能提交url地址格式-->
- url:<input type="url" name="url" required=""/><input type="submit" /><br />
- email:<input type="email" name="email" required=""/><input type="submit" /><br />
- date(谷歌瀏覽器):<input type="date" name="date" /><br />
- time(谷歌瀏覽器):<input type="time" name="time" /><br />
- datetime-local:<input type="datetime-local" name="datetime" value="2016-05-26T22:31:30"/><br />
- <!--日期時(shí)間類(lèi)型的step屬性:?jiǎn)螕粽{(diào)整時(shí)對(duì)選擇值多大限定-->
- step:<input type="date" step="3" /><br /><hr />
- number:<input type="number" value="25" min="10" min="20" max="30" step="2" /><br />
- range:<input type="range" value="25" min="10" max="100" step="5" /><br />
- search:<input type="search"/><br />
- tel:<input type="tel" /><br />
- color:<input type="color" /><br />
- <hr />
- output元素的追加:
- <form id="testform">
- 請(qǐng)選擇一個(gè)值:<input type="range" id="range" min="5" max="100" step="5" value="10" onchange="out();"/>
- <output id="out">10</output>
- </form>
- </body>
- </html>
- <script type="text/javascript">
- function setValue(){
- var lable=document.getElementById("label");
- var txtbox=lable.control;//通過(guò)control該屬性來(lái)訪問(wèn)該表單元素
- txtbox.value="213001";
- }
- //indeterminate測(cè)試設(shè)置為true
- var cb=document.getElementById("cb");
- cb.indeterminate=true;
- //選擇的值output輸出
- function out(){
- Debug;
- var number=document.getElementById("range").value;
- document.getElementById("out").value=number;
- }
- </script>
念念不忘,必有回響。技術(shù)成就夢(mèng)想!
以上這篇html5表單及新增的改良元素詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章

HTML5實(shí)現(xiàn)的移動(dòng)端購(gòu)物車(chē)自動(dòng)結(jié)算功能示例代碼
本文介紹HTML5實(shí)現(xiàn)移動(dòng)端購(gòu)物車(chē)自動(dòng)結(jié)算,通過(guò)WebStorage、事件監(jiān)聽(tīng)、DOM操作等技術(shù),確保實(shí)時(shí)更新與數(shù)據(jù)同步,優(yōu)化性能及無(wú)障礙性,提升用戶(hù)體驗(yàn),感興趣的朋友一起看看吧2025-06-18- 在HTML5中,<button>標(biāo)簽用于定義一個(gè)可點(diǎn)擊的按鈕,它是創(chuàng)建交互式網(wǎng)頁(yè)的重要元素之一,本文將深入解析HTML5中的<button>標(biāo)簽,詳細(xì)介紹其屬性、樣式以及實(shí)際2025-06-18
基于 HTML5 Canvas 實(shí)現(xiàn)圖片旋轉(zhuǎn)與下載功能(完整代碼展示)
本文將深入剖析一段基于 HTML5 Canvas 的代碼,該代碼實(shí)現(xiàn)了圖片的旋轉(zhuǎn)(90 度和 180 度)以及旋轉(zhuǎn)后圖片的下載功能,通過(guò)對(duì)代碼的解讀,我們可以學(xué)習(xí)到如何利用 Canvas API2025-06-18
HTML5 getUserMedia API網(wǎng)頁(yè)錄音實(shí)現(xiàn)指南示例小結(jié)
本教程將指導(dǎo)你如何利用這一API,結(jié)合Web Audio API,實(shí)現(xiàn)網(wǎng)頁(yè)錄音功能,從獲取音頻流到處理和保存錄音,整個(gè)過(guò)程將逐步詳解,此外,還討論了getUserMedia API的使用限制和最2025-06-16- HTML5的搜索框是一個(gè)強(qiáng)大的工具,能夠有效提升用戶(hù)體驗(yàn),通過(guò)結(jié)合自動(dòng)補(bǔ)全功能和適當(dāng)?shù)臉邮?,可以?chuàng)建出既美觀又實(shí)用的搜索界面,這篇文章給大家介紹HTML5 搜索框Search Box2025-06-13
- Checkbox是HTML5中非常重要的表單元素之一,通過(guò)合理使用其屬性和樣式自定義方法,可以為用戶(hù)提供豐富多樣的交互體驗(yàn),這篇文章給大家介紹HTML5中Checkbox標(biāo)簽的深入全面解2025-06-13
HTML5無(wú)插件拖拽圖片上傳功能實(shí)現(xiàn)過(guò)程
本實(shí)例展示了一種基于HTML5技術(shù)的圖片上傳功能,無(wú)需外部插件即可通過(guò)拖放圖片實(shí)現(xiàn)上傳,涉及到HTML5的拖放API和File API,以及使用CSS來(lái)增強(qiáng)用戶(hù)界面的交互性和視覺(jué)反饋,2025-05-16HTML5 定位大全之相對(duì)定位、絕對(duì)定位和固定定位
在HTML5和CSS中,定位(positioning)是控制元素在頁(yè)面上位置的重要機(jī)制,主要有四種定位方式:靜態(tài)定位(static)、相對(duì)定位(relative)、絕對(duì)定位(absolute)和固定定位(fixed),2025-05-13- Microdata作為HTML5新增的一個(gè)特性,它允許開(kāi)發(fā)者在HTML文檔中添加更多的語(yǔ)義信息,以便于搜索引擎和瀏覽器更好地理解頁(yè)面內(nèi)容,本文將探討HTML5中Microdata的使用方法以及2025-04-21
在HTML語(yǔ)法中,表格主要通過(guò)< table >、< tr >和< td >3個(gè)標(biāo)簽構(gòu)成,本文通過(guò)實(shí)例代碼講解HTML5表格語(yǔ)法格式,感興趣的朋友一起看看吧2025-04-21




