HTML5中一些酷炫又有趣的新特性代码整理汇总(html5有哪些新特性和优点)奔走相告

随心笔谈1年前 (2023)发布 admin
114 0



目录一、详情标签二、内容可编辑三、地图四、标记内容五、data-* 属性六、输出标签七、数据列表八、范围(滑块)九、Meter十、Inputs必需的自动对焦使用正则表达式验证颜色选择器

HTML5 是 HyperText Markup Language 5 的缩写,HTML5技术结合了HTML4.01的相关标准并革新,符合现代网络发展要求,在2008年正式发布。HTML5 由不同的技术构成,其在互联网中得到了非常广泛的应用,提供更多增强网络应用的标准机。与传统的技术相比,HTML5 的语法特征更加明显,并且结合了SVG的内容。

HTML5并非仅仅用来表示Web内容,它将 Web带入一个成熟的应用平台,在HTML5平台上,视频、音频、图象、动画,以及同电脑的交互都被标准化。

HTML5自初始版本(2008 年 1 月)以来,我们一直在使用它的几个功能。再次查看HTML5 功能列表。发现一些功能过去用得不多,但现在发现它们很有用。

该标签向用户提供按需详细信息。如果您需要按需向用户显示内容,请使用此标签。默认情况下,小部件是关闭的。打开时,它会展开并显示其中的内容。

该标签用于为它指定一个可见的标题。

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

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>

该标签有助于定义图像映射。图像映射是其中包含一个或多个可点击区域的图像。地图标签带有一个标签来确定可点击区域。可点击区域可以是这些形状、矩形、圆形或多边形区域之一。如果您不指定任何形状,它会考虑整个图像。

<div>
<img src=”https://www.jb51.net/article/circus.jpg” width=”500″ height=”500″ alt=”Circus” usemap=”#circusmap”>

<map name=”circusmap”>
<area shape=”rect” coords=”67,114,207,254″ href=”https://www.jb51.net/article/elephant.htm” rel=”external nofollow” >
<area shape=”rect” coords=”222,141,318, 256″ href=”https://www.jb51.net/article/lion.htm” rel=”external nofollow” >
<area shape=”rect” coords=”343,111,455, 267″ href=”https://www.jb51.net/article/horse.htm” rel=”external nofollow” >
<area shape=”rect” coords=”35,328,143,500″ href=”https://www.jb51.net/article/clown.htm” rel=”external nofollow” rel=”external nofollow” >
<area shape=”circle” coords=”426,409,100″ href=”https://www.jb51.net/article/clown.htm” rel=”external nofollow” rel=”external nofollow” >
</map>
</div>

使用标签突出显示任何文本内容。

<p> 你知道吗,你可以仅使用 HTML 标签 <mark>”突出显示有趣的东西”</mark></p>

使用 css 更改高亮颜色

mark {
background-color: green;
color: #FFFFFF;
}

这些data-*属性用于存储页面或应用程序私有的自定义数据。存储的数据可用于 JavaScript 代码以创建进一步的用户体验。

data-* 属性由两部分组成:

属性名称不应包含任何大写字母,并且必须在前缀“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>
<p id=”msg”></p>
<script>
function reveal() {
let dataDiv=document.getElementById(‘data-attr’);
let value=dataDiv.dataset[‘customAttr’];
//使用getAttribute()它们的完整 HTML 名称(即 data-custom-attr),
//但标准定义了一种更简单的方法:使用dataset属性。
document.getElementById(‘msg’).innerHTML=`<mark>${value}</mark>`;
}
</script>

标签表示的运算的结果。通常,此元素定义将用于显示某些计算的文本输出的区域。

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

标签指定了一个预定义选项列表,并允许用户向其中添加更多选项。它提供了一项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>

是给定滑块类型范围选择器的输入类型。

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

使用标签测量给定范围内的数据。

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

提示不要将标签用于进度指示器类型的用户体验。我们有来自 HTML5的标签。

<label for=”file”>Downloading progress:</label>
<progress id=”file” value=”32″ max=”100″> 32% </progress>

这部分是我们最熟悉的输入类型的用法,如文本、密码等。输入类型的特殊用法很少

将输入字段标记为必填字段。

<input type=”text” id=”username1″ name=”username” required>

通过将光标放在输入元素上自动提供焦点。

<input type=”text” id=”username2″ name=”username”autofocus>

您可以使用正则表达式指定模式来验证输入。

<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}$”>

一个简单的颜色选择器。

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

到此这篇关于HTML5中一些酷炫又有趣的新特性代码整理汇总的文章就介绍到这了,更多相关HTML5新特性代码内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:三个不常见的 HTML5 实用新特性简介

© 版权声明

相关文章