0
私はtreewalkerを使用してページの表を探し、列を挿入し、各行の値に基づいてその列にセルを挿入しようとしています。私はたくさんの研究をしましたが、私は失敗し続けます。正しい方向に私を押し込むヒットがあれば、非常に感謝しています。treewalkerを使用してテーブルを変更
document.ondblclick = addElement;
var i = 1;
function addElement() {
var allTextNodes = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT),
// some temp references for performance
tmptxt,
tmpnode,
// compile the RE and cache the replace string, for performance
cakeRE = "Investment"
replaceValue = "TestReplace";
var allElementNodes = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
// iterate through all text nodes
while (allTextNodes.nextNode()) {
tmpnode = allTextNodes.currentNode;
tmptxt = tmpnode.nodeValue;
tmpnode.nodeValue = tmptxt.replace(cakeRE, replaceValue);
}
// iterate through all Element nodes
while (allElementNodes.nextNode()) {
tmpnode = allElementNodes.currentNode;
//I know this is not even close to real code but I think it explains what i'm trying to do
IF (tmpnode.tagvalue = "table")
{
tmpnode.insertcolumn
}
If (tempnode.tagvalue = "tr" && Row.contains("Active"))
{
pupulate the cell from the previously created column with "Active Pending";
}
}
}
function PopulateTable() {
var table = document.getElementsByTagName("table")[0];
var rows = table.getElementsByTagName("tr")[0];
for(var i = 0; i< rows.length; i++) {
var firstColumn = rows[0].getElementsByTagName("td")[0];
//do your data aggregation here
var newCell = document.createElement("td");
newCell.innerHTML = "some data";//create row here
rows[i].appendChild(newCell);
}
}
ありがとうThomas、私はこれを試してみましょう、私は今それを手伝っています。 – keatklein
こんにちはThomas、newRowメソッドが機能しました。私はこのような新しいセルを各行に追加することを望んでいます(上に追加した新しいコード)。 – keatklein