葉劍 發表於 2020-1-19 17:50:00

HTML5与HTML4的区别

<h1 id="h1_1">HTML5和HTML4在基本语法上的区别?</h1>
<h2 id="h2_2">1. 内容类型(ContentType)</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp;HTML5中的文件扩展符仍然为".html"&nbsp;或 ".htm",内容类型仍然为"text/html"。</p>
<h2 id="h2_3">2. DOCTYPE声明</h2>
<p>HTML4:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;!</span><span style="color: rgba(255, 0, 255, 1)">DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://wwww.w3.org/TR/xhtml1-transitional.dtd"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>HTML5:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;!</span><span style="color: rgba(255, 0, 255, 1)">DOCTYPE html</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<pre><code class="hljs html xml"><span class="hljs-meta">//当使用工具时,也可以在DOCTYPE声明方式中加入SYSSTEM识别符,声明方法如下:</span></code></pre>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;!</span><span style="color: rgba(255, 0, 255, 1)">DOCTYPE HTML SYSTEM "about:legacy-compat"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<h2 id="h2_4">3. 指定的字符编码</h2>
<p>&nbsp;HTML4中使用meta元素的形式指定文件中的字符编码,如下所示:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">meta </span><span style="color: rgba(255, 0, 0, 1)">http-equiv</span><span style="color: rgba(0, 0, 255, 1)">="Content-Type"</span><span style="color: rgba(255, 0, 0, 1)"> content</span><span style="color: rgba(0, 0, 255, 1)">="text/html;charset=UTF-8"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>&nbsp;HTML5中,可以使用&lt;meta&gt;元素直接追加charsetd属性的方式来指定字符编码,如下所示:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">meta </span><span style="color: rgba(255, 0, 0, 1)">charset</span><span style="color: rgba(0, 0, 255, 1)">="UTF-8"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>这2种方式都有效,也可以用前一种方式,但是不能同时混用,下面这种方式是错误的。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">meta </span><span style="color: rgba(255, 0, 0, 1)">charset</span><span style="color: rgba(0, 0, 255, 1)">="UTF-8"</span><span style="color: rgba(255, 0, 0, 1)"> http-equiv</span><span style="color: rgba(0, 0, 255, 1)">="Content-Type"</span><span style="color: rgba(255, 0, 0, 1)"> content</span><span style="color: rgba(0, 0, 255, 1)">="text/html;charset=UTF-8"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<h1 id="h1_5">HTML5中新增元素</h1>
<h2 id="h2_6">新增与结构相关的元素</h2>
<p>section元素表示页面中一个内容区块,&lt;section&gt;...&lt;/section&gt;,HTML4中代码示例&lt;div&gt;...&lt;/div&gt;。</p>
<p>article元素表示页面中一块与上下文不相关的独立内容,&lt;article&gt;...&lt;/article&gt;,HTML4中代码示例&lt;div&gt;...&lt;/div&gt;。</p>
<p>aside元素表示article元素的内容之外的、与article元素的内容相关的辅助信息。&lt;aside&gt;...&lt;/aside&gt;,HTML4中代码示例&lt;div&gt;...&lt;/div&gt;。</p>
<p>header元素表示页面中一个内容区块或整个页面的标题。&lt;header&gt;...&lt;/header&gt;,HTML4中代码示例&lt;div&gt;...&lt;/div&gt;。</p>
<p>hgroup元素用于对整个页面或页面中一个内容区块的标题进行组合。&lt;hgroup&gt;&lt;/hgroup&gt;,HTML4中代码示例&lt;div&gt;...&lt;/div&gt;。</p>
<p>footer元素表示整个页面或页面中一个内容区块的脚注。一般来说,它会包含创作者的姓名、创作日期以及创作者联系信息。&lt;footer&gt;&lt;/footer&gt;,HTML4中代码示例&lt;div&gt;...&lt;/div&gt;。</p>
<p>nav元素表示页面中导航链接的部分,&lt;nav&gt;&lt;/nav&gt;,HTML4中代码示例&lt;ul&gt;...&lt;/ul&gt;。</p>
<p>figure元素表示一段独立的流内容,一般表示文档主体流内容的一个独立单元,使用figcaption元素为figure元素添加标题。</p>
<pre><code class="hljs html xml"><span class="hljs-tag">&lt;<span class="hljs-name">figure&gt;
<span class="hljs-tag">&lt;<span class="hljs-name">figcaption&gt;/...<span class="hljs-tag">&lt;/<span class="hljs-name">figucaption&gt;
<span class="hljs-tag">&lt;<span class="hljs-name">p&gt;...<span class="hljs-tag">&lt;/<span class="hljs-name">p&gt;
<span class="hljs-tag">&lt;/<span class="hljs-name">figure&gt;

//HTML4中的代码示例

<span class="hljs-tag">&lt;<span class="hljs-name">dl&gt;
<span class="hljs-tag">&lt;<span class="hljs-name">h1&gt;...<span class="hljs-tag">&lt;/<span class="hljs-name">h1&gt;
<span class="hljs-tag">&lt;<span class="hljs-name">p&gt;...<span class="hljs-tag">&lt;/<span class="hljs-name">p&gt;
<span class="hljs-tag">&lt;/<span class="hljs-name">dl&gt;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<h2 id="h2_7">其他元素</h2>
<p>video元素,定义视频,比如电影片段或其他视频流。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">//HTML5中代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">video </span><span style="color: rgba(255, 0, 0, 1)">src</span><span style="color: rgba(0, 0, 255, 1)">="movie.ogg"</span><span style="color: rgba(255, 0, 0, 1)"> controls</span><span style="color: rgba(0, 0, 255, 1)">="controls"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>video元素<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">video</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)">


//HTML4中代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">objext </span><span style="color: rgba(255, 0, 0, 1)">type</span><span style="color: rgba(0, 0, 255, 1)">="video/ogg"</span><span style="color: rgba(255, 0, 0, 1)"> data</span><span style="color: rgba(0, 0, 255, 1)">="movie.ogg"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">param </span><span style="color: rgba(255, 0, 0, 1)">name</span><span style="color: rgba(0, 0, 255, 1)">="src"</span><span style="color: rgba(255, 0, 0, 1)"> value</span><span style="color: rgba(0, 0, 255, 1)">="movie.ogg"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">object</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>audio元素,audio元素定义音频,比如音乐或其他音频流。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">//HTML5中代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">audio </span><span style="color: rgba(255, 0, 0, 1)">src</span><span style="color: rgba(0, 0, 255, 1)">="movie.wav"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>video元素<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">audio</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)">


//HTML4中代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">objext </span><span style="color: rgba(255, 0, 0, 1)">type</span><span style="color: rgba(0, 0, 255, 1)">="application/ogg"</span><span style="color: rgba(255, 0, 0, 1)"> data</span><span style="color: rgba(0, 0, 255, 1)">="movie.wav"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">param </span><span style="color: rgba(255, 0, 0, 1)">name</span><span style="color: rgba(0, 0, 255, 1)">="src"</span><span style="color: rgba(255, 0, 0, 1)"> value</span><span style="color: rgba(0, 0, 255, 1)">="movie.wav"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">object</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>embed元素,&nbsp;embed元素用来插入各种多媒体,格式可以是Midi、Wav、AIFF、AU、MP3等。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">//HTML5中代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">embed </span><span style="color: rgba(255, 0, 0, 1)">src</span><span style="color: rgba(0, 0, 255, 1)">="movie.wav"</span> <span style="color: rgba(0, 0, 255, 1)">/&gt;</span><span style="color: rgba(0, 0, 0, 1)">


//HTML4中代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">objext </span><span style="color: rgba(255, 0, 0, 1)">type</span><span style="color: rgba(0, 0, 255, 1)">="application/x-shockwave-flash"</span><span style="color: rgba(255, 0, 0, 1)"> data</span><span style="color: rgba(0, 0, 255, 1)">="movie.wav"</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">object</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>mark元素主要用来在视觉上向用户呈现那些需要突出显示或高亮显示的文字。典型就是在搜索结果中向用户高亮显示搜索关键词。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">//HTML5中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">mark</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">mark</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)">


//HTML4中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">span</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">span</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>progress元素,progress元素表示运行中的进程,可以使用progress元素来显示javascript中耗费时间的函数进程。&lt;meter&gt;&lt;/meter&gt;&nbsp;,这是HTML5中新增功能,HTML4中代码无法实现。</p>
<p>time元素,time元素表示日期或时间,同时可以表示两者。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">//HTML5中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">time</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">time</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)">


//HTML4中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">span</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">span</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>ruby元素,ruby元素表示&nbsp;ruby注释(中文注音或字符),这也是HTML5中新增的功能。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">ruby</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>汉 <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">rt</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;</span><span style="color: rgba(128, 0, 0, 1)">rp</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>(<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">rp</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>...<span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">rp</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>)<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">rp</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">rt</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">ruby</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>rt元素,rt元素表示字符(中文注音或字符)的解释或发音。</p>
<p>rp元素,rp元素在ruby注释中使用,以定义不支持ruby元素的浏览器所显示的内容。</p>
<p>wbr元素,wbr元素表示软换行。wbr元素与br元素的区别是: br元素表示此处必须换行,而wbr元素的意思是浏览器窗口或父级元素的宽度足够宽时不进行换行,而当宽度不够时,主动在此处换行。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">p</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>... <span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">wbr</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">p</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>canvas元素,canvas元素表示图形, 比如图标和其他图像,仅提供画布,但它把一个绘图API展现给客户端javascript,以使脚本想把绘制的东西绘制到这块画布上。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">//HTML5中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">canvas </span><span style="color: rgba(255, 0, 0, 1)">id</span><span style="color: rgba(0, 0, 255, 1)">="myCanvas"</span><span style="color: rgba(255, 0, 0, 1)"> width</span><span style="color: rgba(0, 0, 255, 1)">="200"</span><span style="color: rgba(255, 0, 0, 1)"> height</span><span style="color: rgba(0, 0, 255, 1)">="200"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">canvas</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)">


//HTML4中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">object </span><span style="color: rgba(255, 0, 0, 1)">data</span><span style="color: rgba(0, 0, 255, 1)">="inc/exm.svg"</span><span style="color: rgba(255, 0, 0, 1)"> type</span><span style="color: rgba(0, 0, 255, 1)">="image/svg/svg+xml"</span><span style="color: rgba(255, 0, 0, 1)"> width</span><span style="color: rgba(0, 0, 255, 1)">="200"</span><span style="color: rgba(255, 0, 0, 1)"> height</span><span style="color: rgba(0, 0, 255, 1)">="200"</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">object</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>command元素,command元素表示命令按钮,比如单选按钮、复选框或按钮,这是HTML5中新增的功能。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">command </span><span style="color: rgba(255, 0, 0, 1)">onclick</span><span style="color: rgba(0, 0, 255, 1)">="cut()"</span><span style="color: rgba(255, 0, 0, 1)"> label</span><span style="color: rgba(0, 0, 255, 1)">="cut"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>details元素,details元素表示用户要求得到并且可以得到的细节信息。它可以与summary元素配合使用。summary元素提供标题或图例, 这是HTML5中新增的功能。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">details</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">summary</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>HTML 5<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">summary</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)">
...
</span><span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">details</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>datalist元素,datalist元素表示可选数据的列表,与input元素配合使用,可以制作输出值的下拉列表。这是HTML5中新增的功能。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">datalist</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">datalist</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>datagrid元素,datagrid元素表示可选数据的列表,它以树形的形式来显示,这是HTML5中新增的功能。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">datagrid</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">datagrid</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>keygen元素,keygen元素表示生成密钥,这是HTML5中新增的功能。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">keygen</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>output元素,output元素表示不同类型的输出,比如脚本的输出。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">//HTML5中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">output</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">output</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)">


//HTML4中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">span</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;/</span><span style="color: rgba(128, 0, 0, 1)">span</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>source元素,source元素为媒介元素(比如&lt;video&gt;和&lt;audio&gt;)定义媒介资源。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">//HTML5中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">source</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)">


//HTML4中的代码示例

</span><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">param</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<p>menu元素,menu元素表示菜单列表,当希望列出表单空间时使用该标签,在HTML4中不被推荐使用。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">menu</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">li</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;</span><span style="color: rgba(128, 0, 0, 1)">input </span><span style="color: rgba(255, 0, 0, 1)">type</span><span style="color: rgba(0, 0, 255, 1)">="checkbox"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>RED<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">li</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;</span><span style="color: rgba(128, 0, 0, 1)">li</span><span style="color: rgba(0, 0, 255, 1)">&gt;&lt;</span><span style="color: rgba(128, 0, 0, 1)">input </span><span style="color: rgba(255, 0, 0, 1)">type</span><span style="color: rgba(0, 0, 255, 1)">="checkbox"</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>blue<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">li</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span>
<span style="color: rgba(0, 0, 255, 1)">&lt;/</span><span style="color: rgba(128, 0, 0, 1)">menu</span><span style="color: rgba(0, 0, 255, 1)">&gt;</span></pre>
</div>
<h2 id="h2_8">新增的input元素的类型</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; email、url、number、range、Date Pickers</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; Date Pickers:</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; date(年、月、日)</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; month(月、年)</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; week(周和年)</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; time(时间小时和分钟)</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; datetime(选择时间、日、月、年(UTC时间))</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; datetime-local(选取时间、日、月、年(本地时间))。</p>
<h1 id="h1_9">HTML5中新增属性</h1>
<h2 id="h2_10">&nbsp;&nbsp;&nbsp;&nbsp;表单相关的属性</h2>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 1. 可以对input(type=text)、select、textarea与button元素指定autofocus属性。它是以指定属性的方式让元素在画面打开时自动获得焦点。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 2.&nbsp;可以对input(type=text)与textarea元素指定placeholder属性,它会对用户的输入进行提示,提示用户可以输入的内容。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 3.&nbsp;可以对input(type=text)与textarea元素指定required属性,该属性表示在用户提交的时候进行检查,检查该元素内一定要有输入内容。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 4. 对input新增的属性:autocomplete、min、max、multiple、pattern与step。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 5. 对input和button元素新增新属性:formaction、formenctype、formmethod、formnovalidate与formtarget。为fieldset元素增加了disabled属性,可以把它的子元素设为disabled状态。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 6. 为input、button、form元素增加了novalidate属性,该属性可以取消提交时进行的有关检查,表单可以被无条件地提交。</p>
<h2 id="h2_11">&nbsp;&nbsp;&nbsp;&nbsp;链接相关属性</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1. 为a与area增加了media属性,该属性规定目标URL是什么类型的媒介/设备进行优化的,在鞥在href属性存在时使用。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 2. &nbsp;为area元素增加了hreflang属性与rel属性,以保持与a元素、link元素的一致。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 3. 为link元素增加了新属性sizes。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 4. 为base元素增加了target属性,主要目的是保持与a元素的一致性。</p>
<h2 id="h2_12">&nbsp;&nbsp;&nbsp;&nbsp;其他属性</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1. 为ol元素添加reversed,指定列表倒序显示。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 2. 为meta元素增加charset属性。</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3. 为menu增加 type和label属性。</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4. 为style元素增加scoped属性,用来规定样式的作用范围。</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5. 为script增加async属性 ,定义脚本是否异步执行。</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6. 为html元素增加属性manifest,开发离线web应用程序时它与其他API结合使用,定义一个URL,在这个URL上描述文档的缓存信息。</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7. 为iframe元素增加sandbox、seamless、srcdoc,用来提高页面安全性,防止不信任的web页面执行某些操作。</p>
<p>&nbsp;</p>
<h1 id="h1_13">几个常用的全局属性</h1>
<h2 id="h2_14">&nbsp;&nbsp;&nbsp;&nbsp;全局属性</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 全局属性的概念是HTML5中新增的,是指可以对任何元素都使用的属性。</p>
<h2 id="h2_15">&nbsp;&nbsp;&nbsp;&nbsp;contentEditable</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contentEditable是一个布尔值属性,主要功能是允许用户编辑元素中的内容,所以该元素是可以获得鼠标焦点的元素,而且在点击鼠标后要向用户提供一个插入符号,提示该元素中的内容允许编辑。</p>
<h2 id="h2_16">&nbsp;&nbsp;&nbsp;&nbsp;designMode</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; designMode属性有2个值,"on"和"off",用来指定整个页面是够可编辑,当页面编辑时,任何支持上文的contentEditable属性的元素都变成可编辑状态。</p>
<pre><code class="hljs javascript"><span class="hljs-built_in">document.designMode = <span class="hljs-string">"on";</span></span></code></pre>
<h2 id="h2_17">&nbsp;&nbsp;&nbsp;&nbsp;hidden</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hidden属性类似于input元素中的hidden元素,功能是通知浏览器不渲染该元素,使该元素处于不可见状态。</p>
<h2 id="h2_18">&nbsp;&nbsp;&nbsp;&nbsp;spellcheck</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spellcheck是HTML5针对input(type=text)与textarea这2个文本输入框提供的一个新属性,它对用户输入的文本内容进行拼写和语法检查。&nbsp; spellcheck属性是一个布尔属性值,特别的是使用这个属性时必须声明属性值为true或false。</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 注意!!! 元素为readOnly属性或disabled属性设为true时,不执行拼写检查。</p>
<h2 id="h2_19">&nbsp;&nbsp;&nbsp;&nbsp;tabindex</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tabindex是开发中的一个基本概念,当不断敲击Tab键让窗口或页面中的控件获得焦点,对窗口或页面中的所有控件进行遍历的时候,每一个控件的tabindex表示该控件是第几个被访问到的。作用二是在默认情况下,只有链接元素与表单元素可以通过按键获得焦点。但是有副作用,脚本中执行focus()语句可以获得焦点,该元素也可以通过按Tab键获得焦点。所以把元素tabindex值设为负数(-1)。</p>
<p>&nbsp;</p>
<p>参考资料:</p>
<p><img class="zoom-in-cursor" src="http://static.oschina.net/uploads/space/2016/0830/185854_Rl0W_1040513.jpg" alt="" width="120" height="164"></p>
<p>【中】陆凌牛&nbsp;著 &nbsp;机械工业出版社《HTML5 与 CSS3 权威指南》</p><br><br>
来源:https://www.cnblogs.com/zmlljx/p/12215028.html
頁: [1]
查看完整版本: HTML5与HTML4的区别