讓ie瀏覽器支援html5新標籤的解決方案(使用html5shiv)

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   使用   java   

沒估計錯的話舊版瀏覽器都是不識別這些新增的標籤所以都是用行內元素來處理解決的,所以,有一個解決辦法的突破口就是讓它變成塊狀元素就不會處於同一行了,這樣在新舊瀏覽器都是可以顯示同樣的效果,再者就是讓瀏覽器識別標籤,需要新增標籤,具體解決辦法是:
IE8/IE7/IE6支援通過document.createElement方法產生的標籤,可以利用這一特性讓這些瀏覽器支援HTML5新標籤,代碼如下:
document.createElement(‘新標籤’); / /新增建立新標籤

 

方式一:Coding JavaScript

<!--[if lt IE9]>
<script>
   (function() {
     if (!
     /*@[email protected]*/
     0) return;
     var e = "abbr, article, aside, audio, canvas, datalist, details, dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(‘, ‘);
     var i= e.length;
     while (i--){
         document.createElement(e[i])
     }
})()
</script>
<![endif]—>

將上代碼複製到head部分,記住一定要是head部分(因為IE必須在元素解析前知道這個元素,所以這個js檔案不能在其他位置調用,否則失效)


方式二:使用Google的html5shiv包(推薦)

<!--[if lt IE9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

當然,你也可以把代碼拿出來自己看著辦:

(function(){
if(!/*@[email protected]*/0) return;
var e ="abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(‘,‘),i=e.length;
while(i--){document.createElement(e[i])
}})()

最後在css裡面加上這段:
/*html5*/ article,aside,dialog,footer,header,section,footer,nav,figure,menu{display:block}
主要是讓這些html5標籤成塊狀,像div那樣。

好了,簡單吧,一句話概括就是:引用html5.js  使html5標籤成塊狀.

--------------------------------

參考雷鋒網的原始碼執行個體:

<參考:http://blog.csdn.net/ptyzhu/article/details/19477695 & http://www.th7.cn/web/html-css/201404/29228.shtml>

讓ie瀏覽器支援html5新標籤的解決方案(使用html5shiv)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.