我向 mozilla 目录提交了一个 Firefox 插件,但由于以下原因被拒绝:
item.innerHTML = '<table style="border-collapse: collapse; width: 100%;">'
+ '<tr><td style="line-height: inherit; padding: 0pt; width: 100%;">'
+ word.title
+ '</td></tr>'
+ '</table>';
我与编辑交谈,他告诉我“使用文本节点,然后使用appendChild、textContent等插入它
”
这对我来说听起来完全是胡言乱语,我从未使用过 TextContent、appendChild
等,并且有点迷失。您能否向我展示如何执行上述操作,然后我将在脚本中编辑类似上述内容的其他 13 个实例?
谢谢!
最佳答案
您可能需要按照以下方式做一些事情:
var t = document.createElement("table"),
tb = document.createElement("tbody"),
tr = document.createElement("tr"),
td = document.createElement("td");
t.style.width = "100%";
// note the reverse order of adding child
tr.appendChild(td);
tb.appendChild(tr);
t.appendChild(tb);
// more code to populate table rows and cells
item.appendChild(t);
注意:以这种方式创建表格有一些注意事项,因为浏览器之间的工作方式有所不同。我建议咨询MDN以确定 FF。
关于JavaScript,DOM : appendChild and textContent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6866009/