html5较于xhtml的优点

来源:互联网 发布:电器设计软件 编辑:程序博客网 时间:2024/04/30 01:19
1、支持视频和音频文件的播放。就像支持图片文件一样。
音频文件
<audio controls="controls" autoplay="autoplay">
    <source src="file.ogg" />
    <source src="file.mp3" />
    <a href="file.mp3">Download this file.</a>
</audio>
视频文件
<video controls preload>
    <source src="cohagenPhoneCall.ogv" type="video/ogg"; codecs='vorbis, theora'" />
    <source src="cohagenPhoneCall.mp4" type="video/mp4; 'codecs='avc1.42E01E, mp4a.40.2'" />
<div> your browser is old. <a href="cohagenPhoneCall.mp4">download this video instead.</a> </div>
</video>
 
 
2、必填项属性<input type="text" name="someInput" required="required">
加上required属性即为必填项,无须再通过JS写验证
 
3、直接使用正则表达式<input id="username" type="text" name="username" placeholder="4 <> 10" required="required" autofocus="autofocus" pattern="[A-Za-z]{4,10}">
可以直接在pattern属性中书写正则表达式,无须再通过JS去匹配
 
4、邮箱验证<input id="email" type="email" name="email">新增email类型,无需再通过JS去验证邮箱格式
 
5、占位符属性<input type="email" name="email" placeholder="doug@givethesepeopleair.com">
6、可以不用双引号<h6 id=someid class=myclass> start the reactor. </h6>设置ID和样式时可省略""这种写法了
7......
8......
9......
总言之,html5在xhtml的基础上新增了部分标记,扩展了一些原来标记的属性和类型。从而达到使开发更轻松省事,页面更美观,简洁

原创粉丝点击