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