IE浏览器不支持innerHTML属性动态添加table,可以采用下面方法:
var divNode = document.getElementById(
"div");
var spetr = document.getElementById( "speed");
divNode.removeChild(spetr);
var tr = document.createElement('tr');
var td1 = document.createElement('td');
td1.setAttribute( "height", "35");
// td1.setAttribute("class", "sx1");
td1.className= "sx1";
td1.setAttribute( "style", "padding-top:5px;");
td1.innerHTML= "<strong>我的网速:</strong>";
var td2 = document.createElement('td');
td2.setAttribute( "height", "35");
// td2.setAttribute("class", "sx1");
td2.className= "sx1";
td2.setAttribute( "colSpan", "3");
td2.setAttribute( "style", "padding-top:5px;");
td2.innerHTML= "<div class='yanse'><span style='width:"+loadvar*8/1024*10+ "%; background-color:#fff6b4'></span></div>";
tr.appendChild(td1);
tr.appendChild(td2);
divNode.appendChild(tr);
var spetr = document.getElementById( "speed");
divNode.removeChild(spetr);
var tr = document.createElement('tr');
var td1 = document.createElement('td');
td1.setAttribute( "height", "35");
// td1.setAttribute("class", "sx1");
td1.className= "sx1";
td1.setAttribute( "style", "padding-top:5px;");
td1.innerHTML= "<strong>我的网速:</strong>";
var td2 = document.createElement('td');
td2.setAttribute( "height", "35");
// td2.setAttribute("class", "sx1");
td2.className= "sx1";
td2.setAttribute( "colSpan", "3");
td2.setAttribute( "style", "padding-top:5px;");
td2.innerHTML= "<div class='yanse'><span style='width:"+loadvar*8/1024*10+ "%; background-color:#fff6b4'></span></div>";
tr.appendChild(td1);
tr.appendChild(td2);
divNode.appendChild(tr);
需要注意的是:
(1)class属性不能使用setAttribute,需要采用className
(2)colSpan属性其中需要注意s必须大写,否则样式不能显示。
转载于:https://blog.51cto.com/zhangxu1316/979660