自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

10個(gè)好用的 HTML5 特性

開發(fā)
在本文中,我列出了十個(gè)我過去沒用過的HTML5功能,但現(xiàn)在發(fā)現(xiàn)它們很有用

       [[345137]]

detais 標(biāo)簽
<details>標(biāo)簽向用戶提供按需查看詳細(xì)信息的效果。如果需要按需向用戶顯示內(nèi)容,簡單的做法就是使用此<details>標(biāo)簽。默認(rèn)情況下,它是收起來的,打開后,它將展開并顯示被隱藏的內(nèi)容。

事例:

  1. <details> 
  2.   <summary>Click Here to get the user details</summary> 
  3.   <table
  4.     <tr> 
  5.       <th>#</th> 
  6.       <th>Name</th> 
  7.       <th>Location</th> 
  8.       <th>Job</th> 
  9.     </tr> 
  10.     <tr> 
  11.       <td>1</td> 
  12.       <td>Adam</td> 
  13.       <td>Huston</td> 
  14.       <td>UI/UX</td> 
  15.     </tr> 
  16.   </table
  17. </details> 

運(yùn)行結(jié)果:

技巧
在 GitHub Readme 中使用它來顯示按需的詳細(xì)信息。這是一個(gè)示例https://github.com/atapas/notifyme#properties

內(nèi)容可編輯
contenteditable是可以在元素上設(shè)置以使內(nèi)容可編輯的屬性。它適用于DIV,P,UL等元素。

注意,當(dāng)在元素上沒有設(shè)置contenteditable屬性時(shí),它將從其父元素繼承該屬性。

  1. <h2> Shoppping List(Content Editable) </h2> 
  2.  <ul class="content-editable" contenteditable="true"
  3.      <li> 1. Milk </li> 
  4.      <li> 2. Bread </li> 
  5.      <li> 3. Honey </li> 
  6. </ul> 

運(yùn)行結(jié)果:

技巧
可以讓span或div標(biāo)簽可編輯,并且可以使用css樣式向其添加任何豐富的內(nèi)容。這將比使用輸入字段處理它更好。試試看!

Map
HTML <map> 屬性 與 <area> 屬性一起使用來定義一個(gè)圖像映射(一個(gè)可點(diǎn)擊的鏈接區(qū)域)??牲c(diǎn)擊的區(qū)域可以是這些形狀中的任何一個(gè),矩形,圓形或多邊形區(qū)域。如果不指定任何形狀,則會(huì)考慮整個(gè)圖像。

事例:

  1. <div> 
  2.     <img src="circus.jpg" width="500" height="500" alt="Circus" usemap="#circusmap"
  3.     <map name="circusmap"
  4.         <area shape="rect" coords="67,114,207,254" href="elephant.htm"
  5.         <area shape="rect" coords="222,141,318, 256" href="lion.htm"
  6.         <area shape="rect" coords="343,111,455, 267" href="horse.htm"
  7.         <area shape="rect" coords="35,328,143,500" href="clown.htm"
  8.         <area shape="circle" coords="426,409,100" href="clown.htm"
  9.     </map> 
  10.  </div> 

運(yùn)行結(jié)果:

技巧
map有其自身的缺點(diǎn),但是你可以將其用于視覺演示。

mark 標(biāo)簽

  1. <p> Did you know, you can <mark>"Highlight something interesting"</mark> just with an HTML tag? </p> 

運(yùn)行結(jié)果:

  1. mark { 
  2.   background-color: green; 
  3.   color: #FFFFFF; 

data-* 屬性
data-*屬性用于存儲(chǔ)頁面或應(yīng)用程序?qū)S玫淖远x數(shù)據(jù)??梢栽?JavaScript 代碼中使用存儲(chǔ)的數(shù)據(jù)來創(chuàng)建更多的用戶體驗(yàn)。

data-*屬性由兩部分組成

  • 屬性名不能包含任何大寫字母,并且必須在前綴“data-”之后至少有一個(gè)字符
  • 屬性值可以是任何字符串

事例:

  1. <h2> Know data attribute </h2> 
  2.  <div  
  3.        class="data-attribute"  
  4.        id="data-attr"  
  5.        data-custom-attr="You are just Awesome!">  
  6.    I have a hidden secret!  </div> 
  7.  <button onclick="reveal()">Reveal</button> 

在 JS 中:

  1. function reveal() { 
  2.    let dataDiv = document.getElementById('data-attr'); 
  3.     let value = dataDiv.dataset['customAttr']; 
  4.    document.getElementById('msg').innerHTML = `<mark>${value}</mark>`; 

**注意:**要在 JS 中讀取這些屬性的值,可以通過getAttribute('data-custom-attr')g來獲取,但是標(biāo)準(zhǔn)方式是用dataset來獲取。

技巧
你可以使用它在頁面中存儲(chǔ)一些數(shù)據(jù),然后使用REST調(diào)用將其傳遞給服務(wù)器。

output 標(biāo)簽
<output> 標(biāo)簽表示計(jì)算或用戶操作的結(jié)果。

  1. <form oninput="x.value=parseInt(a.value) * parseInt(b.value)"
  2.    <input type="number" id="a" value="0"
  3.           * <input type="number" id="b" value="0"
  4.                 = <output name="x" for="a b"></output
  5. </form> 

技巧
如果要在客戶端 JS 中執(zhí)行任何計(jì)算,并且希望結(jié)果反映在頁面上,可以使用<output>,這樣就無需使用getElementById()獲取元素的額外步驟。

datalist
<datalist>元素包含了一組<option>元素,這些元素表示其它表單控件可選值.

事例:

  1. <form action="" method="get"
  2.     <label for="fruit">Choose your fruit from the list:</label> 
  3.     <input list="fruits" name="fruit" id="fruit"
  4.         <datalist id="fruits"
  5.            <option value="Apple"
  6.            <option value="Orange"
  7.            <option value="Banana"
  8.            <option value="Mango"
  9.            <option value="Avacado"
  10.         </datalist> 
  11.      <input type="submit"
  12.  </form>   

技巧
dataList的表現(xiàn)很像是一個(gè)select下拉列表,但它只是提示作用,并不限制用戶在input輸入框里輸入什么

select標(biāo)簽創(chuàng)建了一個(gè)菜單。菜單里的選項(xiàng)通option標(biāo)簽指定。一個(gè)select元素內(nèi)部,必須包含一個(gè)option元素,

總的來說就是,它們都可以顯示出一個(gè)下拉表單框,但是select標(biāo)簽只能在它提供的選項(xiàng)中選擇,而datalist不僅可以讓你選擇,還可以讓你自己輸入其它的選項(xiàng)。

Range(Slider)
range是一種 input 類型,給定一個(gè)滑塊類型的范圍選擇器。

  1. <form method="post"
  2.     <input  
  3.          type="range"  
  4.          name="range"  
  5.          min="0"  
  6.          max="100"  
  7.          step="1"  
  8.          value="" 
  9.          onchange="changeValue(event)"/> 
  10.  </form> 
  11.  <div class="range"
  12.       <output id="output" name="result">  </output
  13.  </div> 

meter
<meter>元素用來顯示已知范圍的標(biāo)量值或者分?jǐn)?shù)值。

  1. <label for="home">/home/atapas</label> 
  2. <meter id="home" value="4" min="0" max="10">2 out of 10</meter><br> 
  3. <label for="root">/root</label> 
  4. <meter id="root" value="0.6">60%</meter><br> 

技巧
不要將<meter>用作進(jìn)度條來使用,進(jìn)度條對(duì)應(yīng)的<Progress> 標(biāo)簽。

  1. <label for="file">Downloading progress:</label> 
  2. <progress id="file" value="32" max="100"> 32% </progress> 

Inputs
對(duì)于input標(biāo)簽類型,最常見的有 text,password 等等,下面列舉一些比較少見的語法。

required
要求輸入字段必填。

  1. <input type="text" id="username1" name="username" required> 

autofocus
文本輸入字段被設(shè)置為當(dāng)頁面加載時(shí)獲得焦點(diǎn):

  1. <input type="text" id="username2" name="username" required autofocus> 

用正則表達(dá)式驗(yàn)證
可以使用regex指定一個(gè)模式來驗(yàn)證輸入。

  1. <input type="password"  
  2.             name="password"  
  3.             id="password"  
  4.             placeholder="6-20 chars, at least 1 digit, 1 uppercase and one lowercase letter"  
  5.             pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$" autofocus required> 

Color picker
一個(gè)簡單的顏色選擇器。

  1. <input type="color" onchange="showColor(event)"
  2. <p id="colorMe">Color Me!</p> 

 

責(zé)任編輯:姜華 來源: 今日頭條
相關(guān)推薦

2014-03-18 09:20:17

HTML5移動(dòng)開發(fā)

2011-01-27 13:08:57

HTML5JavascriptWeb

2014-12-22 15:02:48

HTML5移動(dòng)應(yīng)用開發(fā)

2012-04-05 13:19:06

WEBHTML5

2011-03-28 17:58:17

ibmdwHTML5

2015-04-21 14:54:39

HTML5混合式App

2013-01-24 10:26:04

HTML5HTML 5HTML5的未來

2011-09-27 17:37:22

2023-07-24 13:22:35

VideoHTML5Web

2011-04-22 15:02:19

HTML5Dojo

2011-07-19 13:39:20

iOS HTML5

2011-05-13 17:36:05

HTML

2015-09-22 13:25:46

Web開發(fā)者HTML5工具

2012-04-04 12:57:37

HTML5

2012-03-30 09:45:07

WEBHTML5

2012-06-05 10:48:23

2019-12-26 15:12:14

Html5框架Web

2011-10-14 09:53:52

HTML 5

2018-05-18 15:05:25

JavaJava 10新特性

2015-07-27 09:48:24

最棒 HTML5 框架
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)