function insertRow (label) {
var list = document.getElementById('list');
var row = list.insertRow();
var cell1 = row.insertCell(0);
var slash = document.createTextNode('/');
var upButton = document.createElement('button');
var downButton= document.createElement('button');
upButton.innerHTML = "Up";
downButton.innerHTML = "Down";
cell1.style.borderBottom = "2px solid black";
cell1.style.borderLeft = "2px solid black";
cell1.appendChild(upButton);
cell1.appendChild(slash);
cell1.appendChild(downButton);
}
该函数的最后3行完成了我要查找的操作,但是对我来说,这似乎并不是正确的方法。这是我的第一个DOM脚本项目。
最佳答案
我们所有人都生活在“只要代码起作用,那就好”的世界。但是,很少有建议:
不确定JQuery是否适合您,但是它可以帮助开发独立于浏览器的代码,否则,您最终将在所有浏览器中测试此(javascript)代码。
创建模板HTML并将其附加到单元格。代码行数将大大减少,并且代码更具可读性。
不要使用内联样式。相反,创建一个CSS类并使用className方法