如何在IE中使用HTML 5元素
作者:阿汐
在HTML 5還未正式投入使用,在大多數(shù)瀏覽器中還是未知元素的這個(gè)時(shí)候,有一個(gè)簡單的方法可以在IE中使用HTML 5元素。那就是,使用JS創(chuàng)建未知元素。
Sjoerd Visscher 發(fā)現(xiàn)了一個(gè)簡潔的方法讓樣式在 IE 中作用到未知的元素上——僅需 JS 創(chuàng)建此未知元素即可:
- document.createElement(elementName)
同理(對(duì)于 IE 來說 HTML 5元素即是未知元素),該方法也可順延到 HTML 5 的元素上(詳細(xì)見:John Resig 寫的 《HTML5 Shiv》 一文):
- < html>
- < head>
- < style>section { color: red; }< /style>
- < script>document.createElement("section")< /script>
- < /head>
- < body>
- < section>Hello World!< /section>
- < /body>
- < /html>
在 IE 中,為了更方便使用 HTML 5元素,我們可以引入這樣的腳本:
- (function(){
- // from: http://dean.edwards.name/weblog/2007/03/sniff/
- if(!/*@cc_on!@*/0) return;
- var html5 = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,
- eventsource,figure,footer,hgroup,header,mark,menu,meter,nav,output,
- progress,section,time,video".split(',');
- for(var i = 0, len = html5.length; i < len; i++ )
- document.createElement(html5[i]);
- }
- })();
詳細(xì)具體應(yīng)用的案例如下:
原文:http://www.planabc.net/2009/06/13/how_to_use_html5_elements_in_ie/
【編輯推薦】
責(zé)任編輯:yangsai
來源:
51CTO論壇