window.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');
document.write("我是tbody"+tbody.nodeName);
var tr = obj.parentNode.parentNode;
document.write("我是tr"+tr.nodeName);
// 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 | 刘小芳 | 删除 |
其中下面删除行这个函数,因为不理解原参考代码中的
function deleteRow(obj){
var tbody = document.getElementById('table').lastChild; //这行获取的是TALBE标签的子节点,应该是
标签,为什么通过下列代码测试时发现是TBODY标签“document.write("我是tbody"+tbody.nodeName);”var tr = obj.parentNode.parentNode;// obj参数应该是标签,那么tr这变量应该是标签,那么,这到底是怎么回事,我哪里理解错误了??是真的隐藏了TBODY这样一个标签么?如果两个语句获取的都是标签,那下面这个句子应该是错误的吧??
tbody.removeChild(tr);
}
document.write("我是tr"+tr.nodeName);
// tbody.removeChild(tr);
}