ie8不支持html5,若是想要ie8支持html5,有兩種方式:1、引用google的html5.js文件,并將代碼放到head標(biāo)簽區(qū)間;2、通過添加“while (i–){document.createElement(e[i])}”代碼實(shí)現(xiàn)支持HTML5元素。
本教程操作環(huán)境:Windows10系統(tǒng)、HTML5版、Dell G3電腦。
ie8支持html5嗎?
不支持。
但是讓IE(ie6/ie7/ie8)支持HTML5元素,我們可以在HTML頭部添加以下JavaScript,這是一個(gè)簡(jiǎn)單的document.createElement聲明,利用條件注釋針對(duì)IE來調(diào)用這個(gè)js文件。Opera,F(xiàn)ireFox等其他非IE瀏覽器就會(huì)忽視這段代碼,也不會(huì)存在http請(qǐng)求。
方式一:引用google的html5.js文件,代碼內(nèi)容可以自己下載下來看。
<!–[if lt IE9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]–>
登錄后復(fù)制
將以上代碼放到head標(biāo)簽區(qū)間
方式二:自己coding JS搞定。
<script> (function() { if (! /*@cc_on!@*/ 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>
登錄后復(fù)制
不管你用上面哪中方式,請(qǐng)記得在CSS中進(jìn)行如下定義,目的是讓這些標(biāo)簽成為塊狀元素,just like div。
/*html5*/ article,aside,dialog,footer,header,section,footer,nav,figure,menu{display:block}
登錄后復(fù)制
推薦學(xué)習(xí):《HTML5視頻教程》