扫码关注官方订阅号
我想在文档中添加html标签最初是这样的做的,但是太麻烦。
后来有这样做,可是不兼容ie。
有什么好办法吗?谢谢
欢迎选择我的课程,让我们一起见证您的进步~~
试试这个。
<table id="table"></table>
var str = "<tr><td>1sssss1</td><td>22sss</td></tr><tr><td>1sss1</td><td>22sss</td></tr>"; setTableInnerHTML(document.getElementById('table'), str); function setTableInnerHTML(table, html) { if (navigator && navigator.userAgent.match(/msie/i)) { var temp = table.ownerDocument.createElement('p'); temp.innerHTML = '<table><tbody>' + html + '</tbody></table>'; if (table.tBodies.length == 0) { var tbody = document.createElement("tbody"); table.appendChild(tbody); } table.replaceChild(temp.firstChild.firstChild, table.tBodies[0]); } else { table.innerHTML = html; } }
innerHTML 印象中是兼容 IE6 的啊?是不是 document.body 的问题?换个 dom 节点试试?
http://stackoverflow.com/ques...
By 搬运工
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
试试这个。
innerHTML 印象中是兼容 IE6 的啊?是不是 document.body 的问题?换个 dom 节点试试?
http://stackoverflow.com/ques...
By 搬运工