亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

html5中幾個(gè)不容錯(cuò)過(guò)的api或者tips小結(jié)

  發(fā)布時(shí)間:2013-01-04 11:21:26   作者:佚名   我要評(píng)論
之前的一直有關(guān)注一些HTML 5中的值得關(guān)注但少用的API或者tips,這次繼續(xù)小結(jié)一些,有需要的朋友可以參考下,希望可以幫助你們
之前的博文中,一直有關(guān)注一些HTML 5中的值得關(guān)注但少用的API或者tips,這次繼續(xù)小結(jié)一些。
1)element.classList
詳細(xì)的可以參考
https://developer.mozilla.org/en-US/docs/DOM/element.classList
這里簡(jiǎn)單說(shuō)下,它其實(shí)是一個(gè)快速對(duì)某個(gè)元素的class進(jìn)行操作的新的DOM API了,比如
包括了add,remove,toggle,contains的方法,比如
myDiv.classList.add('myCssClass');
myDiv.classList.remove('myCssClass');
myDiv.classList.toggle('myCssClass'); //now it's added
myDiv.classList.toggle('myCssClass'); //now it's removed
myDiv.classList.contains('myCssClass'); //returns true or false
現(xiàn)在的瀏覽器支持情況為:
chrome 8.0+,ie 10,opera 11.5,safari 5.1
2)ContextMenu 上下文菜單 API
這個(gè)API是HTML 5的,用來(lái)可以生成簡(jiǎn)單的可以點(diǎn)擊的上下文菜單,能給用戶快速的選擇和顯示,比如

復(fù)制代碼
代碼如下:

<section contextmenu="mymenu">
<!--
For the purpose of cleanliness,
I'll put my menu inside the element that will use it
-->
<!-- add the menu -->
<menu type="context" id="mymenu">
<menuitem label="Refresh Post" onclick="window.location.reload();" icon="/images/refresh-icon.png"></menuitem>
<menu label="Share on..." icon="/images/share_icon.gif">
<menuitem label="Twitter" icon="/images/twitter_icon.gif" onclick="goTo('//twitter.com/intent/tweet?text=' + document.title + ': ' + window.location.href);"></menuitem>
<menuitem label="Facebook" icon="/images/facebook_icon16x16.gif" onclick="goTo('//facebook.com/sharer/sharer.php?u=' + window.location.href);"></menuitem>
</menu>
</menu>
</section>

3)element.dataset
這個(gè)API用來(lái)獲得鍵值對(duì)的時(shí)候很有用:
比如:

復(fù)制代碼
代碼如下:

<div id="myDiv" data-name="myDiv" data-id="myId" data-my-custom-key="This is the value"></div>

則通過(guò)下面這些可以獲得鍵值對(duì),這個(gè)用在jquery mobile中很實(shí)用:

復(fù)制代碼
代碼如下:

// 獲得元素
var element = document.getElementById("myDiv");
// 獲得id
var id = element.dataset.id;
// 獲得data-my-custom-key"
var customKey = element.dataset.myCustomKey;
// 設(shè)置新的值
element.dataset.myCustomKey = "Some other value";

4)postMessage API
這個(gè)居然在IE 8后就支持了,可以支持在不同domain的iframe中傳遞消息

復(fù)制代碼
代碼如下:

// From window or frame on domain 1, send a message to the iframe which hosts another domain
var iframeWindow = document.getElementById("iframe").contentWindow;
iframeWindow.postMessage("Hello from the first window!");
// From inside the iframe on different host, receive message
window.addEventListener("message", function(event) {
if(event.origin == "http://davidwalsh.name") {
// Log out the message
console.log(event.data);
// Send a message back
event.source.postMessage("Hello back!");
}
]);

5)autofocus
這個(gè)很簡(jiǎn)單了,自動(dòng)focus到控件

復(fù)制代碼
代碼如下:

<input autofocus="autofocus" />
<button autofocus="autofocus">Hi!</button>
<textarea autofocus="autofocus"></textarea>

相關(guān)文章

  • 5 個(gè)強(qiáng)大的HTML5 API 函數(shù)推薦

    本文給大家推薦了5個(gè)html5的新型API函數(shù),包括全屏API(Fullscreen API)、頁(yè)面可見(jiàn)性API(Page Visibility API)、getUserMedia API、電池API(Battery API)、 Link Pref
    2014-11-19
  • HTML5中5個(gè)簡(jiǎn)單實(shí)用的API

    當(dāng)你在人群中談?wù)摰健癏TML5”,你也許會(huì)感覺(jué)到,自己像一位異域舞者或獨(dú)角獸,來(lái)到屋子中間,帶有明顯的“我很酷,我知道它”的意味
    2014-04-28
  • HTML5 通信API 跨域門檻將不再高、數(shù)據(jù)推送也不再是夢(mèng)

    HTML5新增通信相關(guān)兩個(gè)API,跨文檔消息傳輸與WEB Sockets API,跨文檔消息傳輸功能,可以在不同網(wǎng)頁(yè)文檔,不同端口(跨域情況下)進(jìn)行消息傳遞。使用web sockets api 可以
    2013-04-25
  • html5中 media(播放器)的api使用指南

    這篇文章主要介紹了html5中 media(播放器)的api使用指南,需要的朋友可以參考下
    2014-12-26
  • HTML5學(xué)習(xí)筆記之History API

    這系列文章主要是學(xué)習(xí)Html5相關(guān)的知識(shí)點(diǎn),以學(xué)習(xí)API知識(shí)點(diǎn)為入口,由淺入深的引入實(shí)例,讓大家一步一步的體會(huì)"h5"能夠做什么,以及在實(shí)際項(xiàng)目中如何去合理的運(yùn)用達(dá)到使用自
    2015-02-26

最新評(píng)論