我想在文档中添加html标签
最初是这样的做的,但是太麻烦。
<body></body>
<script>
function XX(){
var t1 = document.createElement("table");
var t2 = document.createElement("tr");
var t3 = document.createElement("td");
var t4 = document.createTextNode("11111");
var t5 = document.createElement("td");
var t6 = document.createTextNode("22222");
document.body.appendChild(t1);
t1.appendChild(t2);
t2.appendChild(t3);
t3.appendChild(t4);
t2.appendChild(t5);
t5.appendChild(t6);
t1.setAttribute("border","1");
t1.setAttribute("width","100%");
}
XX();
</script>
后来有这样做,可是不兼容ie。
<script>
window.onload=function x(){
document.body.innerHTML="<table><tr><td>1sssss1</td><td>22sss</td></tr><tr><td>1sss1</td><td>22sss</td></tr></table>"
}
</script>
有什么好办法吗?谢谢
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
试试这个。
innerHTML 印象中是兼容 IE6 的啊?是不是 document.body 的问题?换个 dom 节点试试?
http://stackoverflow.com/ques...
By 搬运工