好吧,这让我整个晚上都很痛苦,我的意思是我已经在这段代码上工作了至少8个小时了。这有什么问题,argggg。
我正在尝试更新所有<span id="column_[row index number]_[column index number]_[layout position number]">以使其递增1,直到下一个id="row_[row index number]" tr element,它应该在其中搜索的tr元素的id为tr_[row index number]_[column index number]_[layout position number],但不知出于什么原因,它给了我问题。它正在更新相同的<span>标记2x,这会将它从期望的值更改为1,这比它应该的值要多…在每个<tr> elements的firstChild <td> element中只有1 <span>标记。我只是不明白为什么它只为其中的一个设置了2倍,而且它似乎是随机的。自相矛盾。
<td id="tdcolumn_[row index number]_[column index number]_[layout position number]>标记中只有1个<span>元素,但由于某些原因,它调用同一标记两次。它应该只调用它一次。阿格。我不明白为什么?
这是我的代码请帮帮我。
// Reorder all columns, if any, in the other rows after this 1.
if (aRowId != 0 && lId.indexOf("tr_" + aRowId) == 0 && rowComplete != aRowId)
{
var tempTr = lTable.childNodes[i].childNodes[p];
while(tempTr.nodeType == 1 && tempTr.nextSibling != null)
{
var tempId = tempTr.getAttribute("id");
if (!tempId) continue;
if (tempId.indexOf("row_") == 0)
{
// All done this row, set it to completed!
rowComplete = aRowId;
break;
}
if (tempTr.hasChildNodes)
{
var doneChilds = false;
// grab the id where tdcolumn_{aRowId}.indexOf = 0.
for (fcTd = 0; fcTd<tempTr.childNodes.length; fcTd++)
{
if (tempTr.childNodes[fcTd].nodeName == '#text') continue;
var tempfcId = tempTr.childNodes[fcTd].getAttribute("id");
if (!tempfcId) continue;
if (tempfcId.indexOf("tdcolumn_" + aRowId) != 0) continue;
// looping through the children in the <td> element here.
if (tempTr.childNodes[fcTd].hasChildNodes)
{
for (x = tempTr.childNodes[fcTd].childNodes.length-1; x>0; x--)
{
if (tempTr.childNodes[fcTd].childNodes[x].nodeName == '#text') continue;
var tempSpanId = tempTr.childNodes[fcTd].childNodes[x].getAttribute("id");
if (!tempSpanId) continue;
if (tempSpanId.indexOf("column_") != 0)
continue;
// alert(tempSpanId);
alert(tempTr.childNodes[fcTd].childNodes[x].nodeName);
var tSpanId = new Array();
tSpanId = tempSpanId.split("_");
if (currColumnId == 0)
{
currColumnId = parseInt(tSpanId[1]);
var incCol = currColumnId;
}
incCol++;
// alert("currColumnId = " + currColumnId + "\n\ntSpanId[1] = " + tSpanId[1] + "\n\nincCol = " + incCol);
// Set the new Id's and Text, after which we can exit the for loop.
tempTr.childNodes[fcTd].childNodes[x].setAttribute("id", "column_" + incCol);
tempTr.childNodes[fcTd].childNodes[x].setAttribute("class", "dp_edit_column");
tempTr.childNodes[fcTd].childNodes[x].innerHTML = oColumnText + " " + incCol;
// tempTr.childNodes[fcTd].setAttribute("id", "tdcolumn_" + aRowId + "_" + (parseInt(tSpanId[1])+1) + "_" + tSpanId[3]);
doneChilds = true;
break;
}
}
else
continue;
if (doneChilds == true)
continue;
}
}
else
continue;
tempTr = tempTr.nextSibling;
}
}请帮帮我,谢谢:)
发布于 2010-05-23 19:08:57
虽然我认为如果没有相关的HTML部分,我无法解决您的问题,但我在您的代码中看到了至少一个错误:
if (doneChilds = true)它的计算结果始终为true。它应该是:
if (doneChilds)顺便说一句,这里不需要getAttribute:
var tempfcId = tempTr.childNodes[fcTd].getAttribute("id");只需使用:
var tempfcId = tempTr.childNodes[fcTd].id;永远不要使用setAttribute设置类名,如下所示:
tempTr.childNodes[fcTd].childNodes[x].setAttribute("class", "dp_edit_column");使用:
tempTr.childNodes[fcTd].childNodes[x].className = "dp_edit_column";(上面一行设置元素的id也是如此)。
https://stackoverflow.com/questions/2891152
复制相似问题