下一页兄弟姐妹问题

发布于 2024-09-02 05:31:29 字数 3740 浏览 11 评论 0原文

好吧,这让我整晚都快要死了,我的意思是我现在已经在这段代码上工作了至少 8 个小时。这是什么问题啊,arggggg。

我正在尝试更新所有 将其递增一,直到下一个 < code>id="row_[行索引号]" tr 元素,应搜索的 tr 元素的 id 为 tr_[行索引号]_[列索引号]_[布局位置号]但由于某些天知道什么原因,它给了我问题。它正在更新相同的 标记 2x,这会将其从所需值更改为比应有值多 1 的值...只有 1 firstChild 内的标记每个 的元素元素。我只是不明白为什么它只为其中 1 个设置 2x,而且它似乎是随机的或其他什么。 arggggg。

这是我的代码,请帮助我...

// 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;
    }
}

请帮助我,谢谢: )

Ok, this has been killing me all night, I mean I've been working on this code for atleast 8 hours now. What is the problem with this, argggg.

I am trying to update all <span id="column_[row index number]_[column index number]_[layout position number]"> to increment it by one up until the next id="row_[row index number]" tr element, The tr elements that it should be searching in has an id of tr_[row index number]_[column index number]_[layout position number] but for some god knows what reason, it gives me issues. It's updating the same <span> tag 2x, and this changes it from the desired value to 1 more than it should be... There's only 1 <span> tag within the firstChild <td> element of each of the <tr> elements. I just don't understand why it is setting it 2x for just 1 of them, and it seems that it's random or something. argggg.

There's only 1 <span> element in the <td id="tdcolumn_[row index number]_[column index number]_[layout position number]> tag, but for some reason, it is calling the same tag twice. It should only call it once. arggg. I don't understand why??

Here's my code someone please help me here...

// 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;
    }
}

Please help me, Thank You :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最丧也最甜 2024-09-09 05:31:29

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

Though I don't think I can solve your problem without the relevant HTML parts, I see at least one error in your code:

if (doneChilds = true)

This always evaluates to true. It should read:

if (doneChilds)

BTW, you don't need getAttribute here:

var tempfcId = tempTr.childNodes[fcTd].getAttribute("id");

Just use:

var tempfcId = tempTr.childNodes[fcTd].id;

Never set a class name using setAttribute, like here:

tempTr.childNodes[fcTd].childNodes[x].setAttribute("class", "dp_edit_column");

Use:

tempTr.childNodes[fcTd].childNodes[x].className = "dp_edit_column";

(the same is true for the line above that one, setting the id of an element).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文