HTML5中一些酷炫又有趣的新特性代碼整理匯總
HTML5 是 HyperText Markup Language 5 的縮寫,HTML5技術(shù)結(jié)合了HTML4.01的相關(guān)標(biāo)準(zhǔn)并革新,符合現(xiàn)代網(wǎng)絡(luò)發(fā)展要求,在2008年正式發(fā)布。HTML5 由不同的技術(shù)構(gòu)成,其在互聯(lián)網(wǎng)中得到了非常廣泛的應(yīng)用,提供更多增強(qiáng)網(wǎng)絡(luò)應(yīng)用的標(biāo)準(zhǔn)機(jī)。與傳統(tǒng)的技術(shù)相比,HTML5 的語法特征更加明顯,并且結(jié)合了SVG的內(nèi)容。
HTML5并非僅僅用來表示W(wǎng)eb內(nèi)容,它將 Web帶入一個(gè)成熟的應(yīng)用平臺(tái),在HTML5平臺(tái)上,視頻、音頻、圖象、動(dòng)畫,以及同電腦的交互都被標(biāo)準(zhǔn)化。
HTML5自初始版本(2008 年 1 月)以來,我們一直在使用它的幾個(gè)功能。再次查看HTML5 功能列表。發(fā)現(xiàn)一些功能過去用得不多,但現(xiàn)在發(fā)現(xiàn)它們很有用。
一、詳情標(biāo)簽
該<details>標(biāo)簽向用戶提供按需詳細(xì)信息。如果您需要按需向用戶顯示內(nèi)容,請(qǐng)使用此標(biāo)簽。默認(rèn)情況下,小部件是關(guān)閉的。打開時(shí),它會(huì)展開并顯示其中的內(nèi)容。
該<summary>標(biāo)簽用于<details>為它指定一個(gè)可見的標(biāo)題。
<details>
<summary>Click Here to get the user details</summary>
<table>
<tr>
<th>#</th>
<th>Name</th>
<th>Location</th>
<th>Job</th>
</tr>
<tr>
<td>1</td>
<td>Adam</td>
<td>Huston</td>
<td>UI/UX</td>
</tr>
<tr>
<td>2</td>
<td>Bob</td>
<td>London</td>
<td>Machine Learning</td>
</tr>
<tr>
<td>3</td>
<td>Jack</td>
<td>Australia</td>
<td>UI Designer</td>
</tr>
<tr>
<td>4</td>
<td>Tapas</td>
<td>India</td>
<td>Blogger</td>
</tr>
</table>
</details>
二、內(nèi)容可編輯
contenteditable是可以在元素上設(shè)置以使內(nèi)容可編輯的屬性。它適用于 DIV、P、UL 等元素。您必須指定它,例如,<element contenteditable="true|false">。
注意: 當(dāng)contenteditable元素上沒有設(shè)置屬性時(shí),它將從其父元素繼承。
<h2> Shoppping List(Content Editable) </h2>
<ul class="content-editable" contenteditable="true">
<li> 1. Milk </li>
<li> 2. Bread </li>
<li> 3. Honey </li>
</ul>
三、地圖
該<map>標(biāo)簽有助于定義圖像映射。圖像映射是其中包含一個(gè)或多個(gè)可點(diǎn)擊區(qū)域的圖像。地圖標(biāo)簽帶有一個(gè)<area>標(biāo)簽來確定可點(diǎn)擊區(qū)域??牲c(diǎn)擊區(qū)域可以是這些形狀、矩形、圓形或多邊形區(qū)域之一。如果您不指定任何形狀,它會(huì)考慮整個(gè)圖像。
<div>
<img src="circus.jpg" width="500" height="500" alt="Circus" usemap="#circusmap">
<map name="circusmap">
<area shape="rect" coords="67,114,207,254" href="elephant.htm" rel="external nofollow" >
<area shape="rect" coords="222,141,318, 256" href="lion.htm" rel="external nofollow" >
<area shape="rect" coords="343,111,455, 267" href="horse.htm" rel="external nofollow" >
<area shape="rect" coords="35,328,143,500" href="clown.htm" rel="external nofollow" rel="external nofollow" >
<area shape="circle" coords="426,409,100" href="clown.htm" rel="external nofollow" rel="external nofollow" >
</map>
</div>
四、標(biāo)記內(nèi)容
使用<mark>標(biāo)簽突出顯示任何文本內(nèi)容。
<p> 你知道嗎,你可以僅使用 HTML 標(biāo)簽 <mark>"突出顯示有趣的東西"</mark></p>
使用 css 更改高亮顏色
mark {
background-color: green;
color: #FFFFFF;
}
五、data-* 屬性
這些data-*屬性用于存儲(chǔ)頁面或應(yīng)用程序私有的自定義數(shù)據(jù)。存儲(chǔ)的數(shù)據(jù)可用于 JavaScript 代碼以創(chuàng)建進(jìn)一步的用戶體驗(yàn)。
data-* 屬性由兩部分組成:
屬性名稱不應(yīng)包含任何大寫字母,并且必須在前綴“data-”之后至少長一個(gè)字符
屬性值可以是任何字符串
<h2> Know data attribute </h2>
<div
class="data-attribute"
id="data-attr"
data-custom-attr="You are just Awesome!">
I have a hidden secret!
</div>
<button onclick="reveal()">Reveal</button>
<p id="msg"></p>
<script>
function reveal() {
let dataDiv = document.getElementById('data-attr');
let value = dataDiv.dataset['customAttr'];
//使用getAttribute()它們的完整 HTML 名稱(即 data-custom-attr),
//但標(biāo)準(zhǔn)定義了一種更簡單的方法:使用dataset屬性。
document.getElementById('msg').innerHTML = `<mark>${value}</mark>`;
}
</script>六、輸出標(biāo)簽
<output>標(biāo)簽表示的運(yùn)算的結(jié)果。通常,此元素定義將用于顯示某些計(jì)算的文本輸出的區(qū)域。
<form oninput="x.value=parseInt(a.value) * parseInt(b.value)"> <input type="number" id="a" value="0"> * <input type="number" id="b" value="0"> = <output name="x" for="a b"></output> </form>
七、數(shù)據(jù)列表
<datalist>標(biāo)簽指定了一個(gè)預(yù)定義選項(xiàng)列表,并允許用戶向其中添加更多選項(xiàng)。它提供了一項(xiàng)autocomplete功能,允許您通過預(yù)先輸入獲得所需的選項(xiàng)。
<form action="" method="get">
<label for="fruit">Choose your fruit from the list:</label>
<input list="fruits" name="fruit" id="fruit">
<datalist id="fruits">
<option value="Apple">
<option value="Orange">
<option value="Banana">
<option value="Mango">
<option value="Avacado">
</datalist>
<input type="submit">
</form>
八、范圍(滑塊)
range是給定滑塊類型范圍選擇器的輸入類型。
<form method="post">
<input
type="range"
name="range"
min="0"
max="100"
step="1"
value=""
onchange="changeValue(event)"/>
</form>
<div class="range">
<output id="output" name="result"> </output>
</div>
九、Meter
使用<meter>標(biāo)簽測量給定范圍內(nèi)的數(shù)據(jù)。
<label for="home">/home/atapas</label> <meter id="home" value="4" min="0" max="10">2 out of 10</meter><br> <label for="root">/root</label> <meter id="root" value="0.6">60%</meter><br>
提示不要將
<meter>標(biāo)簽用于進(jìn)度指示器類型的用戶體驗(yàn)。我們有來自 HTML5的<Progress>標(biāo)簽。
<label for="file">Downloading progress:</label> <progress id="file" value="32" max="100"> 32% </progress>
十、Inputs
這部分是我們最熟悉的輸入類型的用法,如文本、密碼等。輸入類型的特殊用法很少
必需的
將輸入字段標(biāo)記為必填字段。
<input type="text" id="username1" name="username" required>
自動(dòng)對(duì)焦
通過將光標(biāo)放在輸入元素上自動(dòng)提供焦點(diǎn)。
<input type="text" id="username2" name="username"autofocus>
使用正則表達(dá)式驗(yàn)證
您可以使用正則表達(dá)式指定模式來驗(yàn)證輸入。
<input type="password"
name="password"
id="password"
placeholder="6-20 chars, at least 1 digit, 1 uppercase and one lowercase letter"
pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$">
顏色選擇器
一個(gè)簡單的顏色選擇器。
<input type="color" onchange="showColor(event)"> <p id="colorMe">Color Me!</p>
到此這篇關(guān)于HTML5中一些酷炫又有趣的新特性代碼整理匯總的文章就介紹到這了,更多相關(guān)HTML5新特性代碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
HTTP與HTTPS超文本傳輸協(xié)議的區(qū)別是什么
隨著越來越多的網(wǎng)站使用HTTPS加密,現(xiàn)在HTTPS的使用已經(jīng)成了硬性要求了。雖然說https是http的安全版,但兩者還是有不少區(qū)別的。本文從https、http的概念和原理入手,講解他們的不同,讓讀者朋友能夠真正理解。2022-12-12
DIV+CSS經(jīng)常用到的屬性、參數(shù)及說明
用過DIV+CSS seo教程布局網(wǎng)站的人都會(huì)喜歡上這種方式,雖然開始沒有用傳統(tǒng)的table直觀,但用習(xí)慣了就會(huì)感覺出DIV+CSS的優(yōu)越。實(shí)際應(yīng)用中我搜索了DIV+CSS的常用定義項(xiàng),并對(duì)其參數(shù)作了歸納和說明,與喜歡DIV+CSS的朋友共享。2008-09-09
Firefox2中輸入框丟失光標(biāo)bug的解決方法
在Firefox2中某些情況下輸入框雖然可以輸入,但在獲取焦點(diǎn)時(shí)沒有文本輸入光標(biāo)的顯示,這個(gè)是非常惡心的bug,非常容易讓表單使用者有一種不能輸入的錯(cuò)覺,即使后來嘗試知道可以輸入,但也無法判斷光標(biāo)定位在哪兒。2008-05-05

