html 5中几个不容错过的api
来源:互联网 发布:迅雷看看 mac 编辑:程序博客网 时间:2024/05/22 17:34
转自: http://jackyrong.iteye.com/blog/1687977
1) element.classList
详细的可以参考
https://developer.mozilla.org/en-US/docs/DOM/element.classList
这里简单说下,它其实是一个快速对某个元素的class进行操作的新的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
现在的浏览器支持情况为:
chrome 8.0+,ie 10,opera 11.5,safari 5.1
2) ContextMenu 上下文菜单 API
这个API是HTML 5的,用来可以生成简单的可以点击的上下文菜单,能给用户快速的选择和显示,比如
- <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
这个API用来获得键值对的时候很有用:
比如:
- <div id="myDiv" data-name="myDiv" data-id="myId" data-my-custom-key="This is the value"></div>
则通过下面这些可以获得键值对,这个用在jquery mobile中很实用:
- // 获得元素
- var element = document.getElementById("myDiv");
- // 获得id
- var id = element.dataset.id;
- // 获得data-my-custom-key"
- var customKey = element.dataset.myCustomKey;
- // 设置新的值
- element.dataset.myCustomKey = "Some other value";
4 postMessage API
这个居然在IE 8后就支持了,可以支持在不同domain的iframe中传递消息
- // 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
这个很简单了,自动focus到控件
<input autofocus="autofocus" />
<button autofocus="autofocus">Hi!</button>
<textarea autofocus="autofocus"></textarea>
- html 5中几个不容错过的api
- 人生中不容错过的几个创业佳期
- 欧美嘉分享旅行中不容错过的“怪异”水果
- 不容错过的网络技术资源
- 一些不容错过的好书
- 不容错过的华为5G十二大DEMO
- 不容错过的一款很棒的机器人
- 不容错过的虚拟化工具
- Transformers:不容错过的精彩大片
- 不容错过的UMPC/MID/电子书方案
- android 开发不容错过的网站
- 你不容错过的30个人生哲理!!!(
- 五个不容错过的Linux命令行技巧
- 不容错过的css代码经典
- 开发者不容错过的免费资源库
- 五个不容错过的Linux命令行技巧
- 不容错过的10段CSS代码
- 那些不容错过的Xcode插件
- Linux服务器中部署配置apache,tomcat,jdk,mysql
- poj 2352 Stars
- ibatis和hibernate的比较
- 【算法题】字符串的全排列
- C#应用程序运行时候检测Framework安装
- html 5中几个不容错过的api
- DBA链接
- Businees Intelligence Development Studio 创建 Time Dimension
- Change Host Name or Port Num in R12 EBS
- VI命令
- web.xml里<filter-mapping>中的<dispatcher>作用
- 打印杨辉三角
- 一个简单的多线程
- ‘string’ does not name a type 错误解析