问题:
tb为一个table
var row = tb.rows[0];
var cell=row.insertCell(row.cells.length);
cell.innerHTML = "aaaa";
cell.style.display = "";
cell.style.cursor = "pointer";
cell.onmouseover = "mOver(this)";
cell.onmouseout = "mOut(this)";
cell.onclick = "mClick(this)";
以上是在一个table中加一个单元格 但是
cell.onmouseover = "mOver(this)";
cell.onmouseout = "mOut(this)";
cell.onclick = "mClick(this)";
却无效
也就是说在动态添加的单元格上的事件 无效
解决方法:用eval()函数
cell.setAttribute("onmouseover", eval(function(){mOver(this)}));
cell.setAttribute("onmouseout", eval(function(){mOut(this)}));
cell.setAttribute("onclick", eval(function(){mClick(this)}));
阅读(2975) | 评论(1) | 转发(0) |