html>
new documentwindow.onload = function(){
Highlight();
}
function addOne(obj){
var tbody = document.getElementById('table').lastChild;
var tr = document.createElement('tr');
var td = document.createElement("td");
td.innerHTML = "";
tr.appendChild(td);
td = document.createElement("td");
td.innerHTML = "";
tr.appendChild(td);
td = document.createElement("td");
td.innerHTML = "删除";
tr.appendChild(td);
tbody.appendChild(tr);
Highlight();
}
function deleteRow(obj){
var tbody = document.getElementById('table').lastChild;
var tr = obj.parentNode.parentNode;
tbody.removeChild(tr);
}
function Highlight(){
var tbody = document.getElementById('table').lastChild;
trs = tbody.getElementsByTagName('tr');
for(var i =1;i
trs[i].onmouseover = function(){
this.style.backgroundColor ="#f2f2f2";
}
trs[i].onmouseout = function(){
this.style.backgroundColor ="#fff";
}
}
}
学号 | 姓名 | 操作 |
---|---|---|
xh001 | 王小明 | 删除 |
xh002 | 刘小芳 | 删除 |
在以上代码中,为什么deleteRow这个地方“var tbody = document.getElementById('table').lastChild;”,为什么要强调
lastChild,这个lastChild在这里是什么意思呢?还有Highlight(),为什么也有lastChild?求解。。。