自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在IE中使用HTML 5元素

開發(fā) 前端
在HTML 5還未正式投入使用,在大多數(shù)瀏覽器中還是未知元素的這個(gè)時(shí)候,有一個(gè)簡單的方法可以在IE中使用HTML 5元素。那就是,使用JS創(chuàng)建未知元素。

Sjoerd Visscher 發(fā)現(xiàn)了一個(gè)簡潔的方法讓樣式在 IE 中作用到未知的元素上——僅需 JS 創(chuàng)建此未知元素即可:

  1. document.createElement(elementName) 

同理(對(duì)于 IE 來說 HTML 5元素即是未知元素),該方法也可順延到 HTML 5 的元素上(詳細(xì)見:John Resig 寫的 《HTML5 Shiv》 一文):

  1. < html> 
  2. < head> 
  3. < style>section { color: red; }< /style> 
  4. < script>document.createElement("section")< /script> 
  5. < /head> 
  6. < body> 
  7. < section>Hello World!< /section> 
  8. < /body> 
  9. < /html> 

在 IE 中,為了更方便使用 HTML 5元素,我們可以引入這樣的腳本:

  1. (function(){  
  2.     // from: http://dean.edwards.name/weblog/2007/03/sniff/  
  3.     if(!/*@cc_on!@*/0) return;   
  4.     var html5 = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,  
  5. eventsource,figure,footer,hgroup,header,mark,menu,meter,nav,output,  
  6. progress,section,time,video".split(',');  
  7.     for(var i = 0, len = html5.length; i <  len; i++ )  
  8.         document.createElement(html5[i]);  
  9.     }  
  10. })(); 

詳細(xì)具體應(yīng)用的案例如下:

Moving markup towards HTML5

Test new HTML 5 elements

原文:http://www.planabc.net/2009/06/13/how_to_use_html5_elements_in_ie/

【編輯推薦】

  1. 關(guān)于HTML 5現(xiàn)狀與未來的觀點(diǎn)碰撞
  2. HTML 5中的五個(gè)應(yīng)用亮點(diǎn)
  3. 細(xì)談HTML 5新增的元素
  4. HTML 5倍受青睞,XHTML 2處境尷尬
  5. HTML 5 下一代Web開發(fā)標(biāo)準(zhǔn)詳解
責(zé)任編輯:yangsai 來源: 51CTO論壇
相關(guān)推薦

2011-12-27 15:29:53

HTML 5

2010-06-17 11:38:57

2012-03-07 09:08:00

HTML 5

2011-05-12 09:01:29

HTML5

2011-08-10 09:31:41

Hibernateunion

2021-03-09 07:27:40

Kafka開源分布式

2015-08-27 09:46:09

swiftAFNetworkin

2021-06-09 09:36:18

DjangoElasticSearLinux

2022-05-17 08:25:10

TypeScript接口前端

2022-06-23 08:00:53

PythonDateTime模塊

2024-01-18 08:37:33

socketasyncio線程

2019-09-16 19:00:48

Linux變量

2014-07-02 09:47:06

SwiftCocoaPods

2020-04-09 10:18:51

Bash循環(huán)Linux

2024-09-06 11:34:15

RustAI語言

2020-11-30 11:55:07

Docker命令Linux

2010-07-27 09:44:16

HTML 5

2025-03-21 09:58:59

Python數(shù)據(jù)類型安全

2021-09-10 10:30:22

Java代碼

2023-12-01 09:18:27

AxiosAxios 庫
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)