10个有用的HTML5功能(you may not be using)

一:<detail>标签(提供随需应变的细节给用户

<detail>标签与<summary>标签搭配使用,默认是关闭状态,点击会展开里面的内容。

示例:

<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>
          </table>
  </details>
看到它正常工作

二:contenteditable(可以在元素上设置以使内容可编辑的属性)

它可与DIV,P,UL等元素一起使用。您必须指定类似<element contenteditable="true|false">

注意,如果contenteditable未在元素上设置属性,则会从其父级继承该属性。

 示例:

<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标签(可以帮助定义图像映射)

map标签与<area>标签一起确定可点击区域。可点击区域可以是矩形,圆形或多边形区域中的任何一种。如果未指定任何形状,它将考虑整个图像。

示例:

<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">
        <area shape="rect" coords="222,141,318, 256" href="lion.htm">
        <area shape="rect" coords="343,111,455, 267" href="horse.htm">
        <area shape="rect" coords="35,328,143,500" href="clown.htm">
        <area shape="circle" coords="426,409,100" href="clown.htm">
    </map>
 </div>

四:<mark>标签(标记突出显示任何文本内容)

示例:

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

五:data-*属性(用于存储页面或应用程序专用的自定义数据。)

示例:

<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>

然后在javascript中

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

六:<output>标签(表示的运算的结果)

通常,此元素定义一个区域,该区域将用于显示某些计算得出的文本

示例:

<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>

七:<datalist>标签(指定的预先定义的选项列表)

它提供了一项autocomplete功能,使您可以提前输入所需的选项。

示例:

<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>标签(测量给定范围内的数据)

示例:

<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>

十:input

示例:

<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}$" autofocus required>

required:将输入字段标记为必填;

autofocus:自动聚焦;

pattern:正则表达式验证;

 选色器

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

猜你喜欢

转载自blog.csdn.net/baidu_39043816/article/details/108529848
今日推荐