nextSibling问题

时间:2010-05-23 09:02:13

标签: javascript dom nodes siblings

好的,这已经让我彻夜难眠了,我的意思是我已经在这个代码上工作了至少8个小时了。这有什么问题,argggg。

我正在尝试更新所有<span id="column_[row index number]_[column index number]_[layout position number]">以将其递增一直到下一个id="row_[row index number]" tr element,它应该搜索的tr元素的id为{{1但是对于某些上帝知道是什么原因,它给了我一些问题。它正在更新相同的tr_[row index number]_[column index number]_[layout position number]代码2x,这会将其从所需的值更改为1以上...在每个<span>内只有1 <span>个标记{ {1}}。我只是不明白为什么它只为它们中的一个设置它2x,而且它似乎是随机的或者其他东西。 argggg。

firstChild <td> element标记中只有一个<tr> elements元素,但由于某种原因,它会两次调用相同的标记。它应该只调用一次。 arggg。我不明白为什么??

这是我的代码有人请在这里帮助我......

<span>

请帮助我,谢谢你:)

1 个答案:

答案 0 :(得分:2)

虽然我认为没有相关的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