HTML5學習筆記簡明版(7):新增屬性(2),html5學習筆記

來源:互聯網
上載者:User

HTML5學習筆記簡明版(7):新增屬性(2),html5學習筆記
dirname屬性

input 和 textarea 元素有了一個新元素 dirname,用於使用者所設定的提交的方向性的控制(譯註,即書寫的方向性,ltr或rtl)。

<form action="addcomment.cgi" method=post> <p><label>Comment: <input type=text name="comment" dirname="comment.dir" required></label></p> <p><button name="mode" type=submit value="add">Post Comment</button></p></form>

 

使用者提交的時候,瀏覽器會接收到3個參數,分別是:comment, comment.dir和mode,類似下面這樣:comment=Hello&comment.dir=ltr&mode=add

如果是阿拉伯文的瀏覽器,輸入的是阿拉伯文مرحبًا的話,那傳回的參數就應該是這樣的:

comment=%D9%85%D8%B1%D8%AD%D8%A8%D9%8B%D8%A7&comment.dir=rtl&mode=add

 textarea下的maxlength和wrap屬性

textarea新增的maxlength和input的maxlength是一樣的,都是限制最大長度的。

新增的wrap屬性為枚舉值(soft/hard),意思分別是:

  • hard:自動硬斷行符號換行,換行標記一同被傳送到伺服器中去,必須與cols同時使用才能判斷多少字元換行;
  • soft:自動軟斷行符號換行,換行標記不會傳送到伺服器中去
 form下的novalidate屬性

新增屬性novalidate的意思是允許form表單不驗證即可提交(不用管form裡的元素是否有驗證條件,例如required, min, max等)。

例子代碼:

<form action="demo_form.asp" novalidate="novalidate">  E-mail: <input type="email" name="user_email" />  <input type="submit" /></form>

 

還有一種用法是,同一個form裡有多個submit按鈕,可以針對某個按鈕設定formnovalidate屬性來忽略驗證,例如:

<form action="editor.cgi" method="post"> <p><label>Name: <input required name=fn></label></p> <p><label>Essay: <textarea required name=essay></textarea></label></p> <p><input type=submit name=submit value="Submit essay"></p> <p><input type=submit formnovalidate name=save value="Save essay"></p> <p><input type=submit formnovalidate name=cancel value="Cancel"></p></form>

 

該form只有在點擊Submit essay按鈕的時候才驗證表單,另外2個按鈕不驗證。

input與button下的新屬性

input和button元素新增加了幾個新屬性(formaction, formenctype, formmethod, formnovalidate和formtarget),如果這些設定這些屬性的話,那所對應的form屬性值將被覆蓋,即input或button所屬的form元素的action, enctype, method, novalidate和target屬性的值將被覆蓋。

例子代碼:

<form action="demo_form.asp" method="get">First name: <input type="text" name="fname" /><br />Last name: <input type="text" name="lname" /><br /><input type="submit" value="Submit" /><input type="submit" formmethod="post" formaction="demo_post.asp" value="Submit" /></form><form action="demo_form.asp" method="get">  First name: <input type="text" name="fname" /><br />  Last name: <input type="text" name="lname" /><br />  <input type="submit" value="Submit" /><br />  <input type="submit" formaction="demo_admin.asp" value="Submit as admin" /></form><form action="demo_form.asp" method="get">  First name: <input type="text" name="fname" /><br />  Last name: <input type="text" name="lname" /><br /><input type="submit" value="Submit" /><input type="submit" formtarget="_blank" value="Submit" /></form>

 

menu下的type和label屬性

menu 元素有了兩個新屬性:type 和 label。它們允許元素轉化成典型使用者介面裡的菜單,並結合全域 contextmenu 屬性提供操作功能表。

 style下的scoped屬性

style 元素有了一個新的 scoped 屬性,用來啟用限定作用範圍的樣式表。在一個這樣的 style 元素裡的樣式規則只應用到當前style元素的父元素根下的子樹,即兄弟樹。

<!-- 這個article正常使用head裡聲明的style --> <article>    <h1>Blah Title Blah</h1>    <p>Blah blah article blah blah.</p></article><article>    <!-- 這裡聲明的style只能讓該article以及子項目使用 -->    <style scoped>        h1 { color: hotpink; }        article { border: solid 1px hotpink; }    </style>    <h1>Blah Title Blah</h1>    <p>Blah blah article blah blah.</p></article>

 

script下的async屬性

async屬性可以讓script載入的腳步非同步執行(即必須是src引用檔案的形式才可以用),例如:

<script type="text/javascript" src="demo_async.js" async="async"></script>

 

有多種執行外部指令碼的方法:

  1. 如果 async="async":指令碼相對於頁面的其餘部分非同步執行(當頁面繼續進行解析時,指令碼將被執行)
  2. 如果不使用 async 且 defer="defer":指令碼將在頁面完成解析時執行
  3. 如果既不使用 async 也不使用 defer:在瀏覽器繼續解析頁面之前,立即讀取並執行指令碼
 html下的manifest屬性

html 元素有了一個新屬性 manifest,指向一個用於結合離線Web應用API的應用程式緩衝清單。

首先,需要先建立manifest檔案

CACHE MANIFEST#This is a commentCACHE #需要緩衝的檔案index.htmlstyle.cssNETWORK: #不需要緩衝的檔案search.phplogin.phpFALLBACK: #資源停用情況下,重新導向的地址/api offline.html

 

然後加該文的地址加到html屬性裡:

<html manifest="/offline.manifest">

 

例子:http://www.mangguo.org/create-offline-html5-web-apps-in-5-easy-steps/

 link下的sizes屬性

link 元素有了一個新的屬性 sizes。可以結合 icon 的關係(通過設定 rel 屬性,可被用於如網站圖示)一起使用來表明被引用表徵圖的大小。因此允許了不同的尺寸的表徵圖。

例子代碼:

<link rel="icon" href="demo_icon.gif" type="image/gif" sizes="16x16" />

 

ol下的reversed屬性

ol 元素有了一個新屬性 reversed。當其存在時,代表列表中的順序為降序。

 iframe下的sanddbox, seamless和srcdoc屬性

iframe 元素有了三個新屬性分別是 sandbox, seamless, 和 srcdoc,用以允許沙箱內容,例如,部落格評論。

例子代碼:

<iframe sandbox src="http://usercontent.example.net/getusercontent.cgi?id=12193"></iframe><iframe sandbox="allow-same-origin allow-forms allow-scripts"        src="http://maps.example.com/embedded.html"></iframe>

Seamless:

<nav><iframe seamless src="nav.include.html"></iframe></nav>

 

video和audio的play屬性

HTML5也使得所有來自HTML4的事件處理屬性(那些形如 onevent-name 的屬性)變成全域屬性,並為其定義的新的事件添加了幾個新的事件處理屬性。比如,媒體元素(video 和 audio)API所使用的 play 事件。

著作權聲明:本文為博主http://www.zuiniusn.com 原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.