我正在尝试根据其文本在特定表格的单元格中添加一个锚点。这是我到目前为止所得到的......
for (var d = 0, max = allTableCells.length; d < max; d++) {
var node = allTableCells[d];
var currentText = node.childNodes[0].nodeValue;
if (currentText === "@WebSecurity.CurrentUserName + 'TEXT'")
node.childNodes[0].nodeValue = '<a name="CP"></a>'
}
}
这里的主要问题似乎是这两行......
if (currentText === "@WebSecurity.CurrentUserName + 'TEXT'")
node.childNodes[0].nodeValue = '<a name="CP"></a>'
如果有人可以帮助我,那就太好了...谢谢
这是页面的完整脚本: var allTableCells = document.getElementsByTagName("td");
for (var i = 0, max = allTableCells.length; i < max; i++) {
var node = allTableCells[i];
var currentText = node.childNodes[0].nodeValue;
if (currentText === "@WebSecurity.CurrentUserName")
node.style.color = "Blue";
node.style.border = "solid"
}
for (var c = 0, max = allTableCells.length; c < max; c++) {
var node = allTableCells[c];
var currentText = node.childNodes[0].nodeValue;
if (currentText === "None")
node.style.color = "black";
node.style.border = "solid"
}
var d, max, node, nodes, currentText, anchor;
for (d = 0, max = allTableCells.length; d < max; d++) {
node = allTableCells[d];
nodes = node.childNodes;
currentText = nodes[nodes.length - 1].nodeValue;
if (@WebSecurity.CurrentUserName === nodes[0].nodeValue && currentText === 'CP') {
anchor = document.createElement('a');
anchor.name = 'CP';
allTableCells[d].insertBefore(anchor, nodes[0]);
}
}
</script>