IE8-下無法識別后續以innerHTML方式添加的自定義標簽


例如要創建一個自定義標簽thetag,事先已document.createElement('thetag'),但后續通過innerHTML的方式添加的該元素,IE8-是不認的。。

createElement + appendChild 則可以。其他瀏覽器各種方式均OK。

<script>document.createElement('thetag');</script>
<thetag id="test1"></thetag>

<script type='text/javascript'>
window.onload=function(){
var div = document.createElement('thetag');
div.id = 'test2';
document.body.appendChild(div);

var html = '<thetag id="test3"></thetag>',
div = document.createElement('div');
div.innerHTML = html;
document.body.appendChild(div);

alert(document.getElementById('test1').id + ' in page');
alert(document.getElementById('test2').id + ' create-append');
alert(document.getElementById('test3').id + ' use innerHTML'); //cause an error in IE8-
}
</script>




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM