代码之家  ›  专栏  ›  技术社区  ›  SoLoGHoST

下一个问题

  •  0
  • SoLoGHoST  · 技术社区  · 16 年前

    好吧,这整晚都在折磨我,我是说,我已经花了至少8个小时的时间编写这个代码了。这有什么问题,阿格。

    我正在尝试更新所有 <span id="column_[row index number]_[column index number]_[layout position number]"> 增加一个直到下一个 id="row_[row index number]" tr element ,它应该搜索的tr元素的ID为 tr_[row index number]_[column index number]_[layout position number] 但对某些上帝知道什么原因,它给了我一些问题。它也在更新 <span> 标记2X,这将它从所需的值更改为1,比它应该的值多…只有 1 <span> 标签内 firstChild <td> element 每一个 <tr> elements . 我只是不明白为什么它只为其中的一个设置了2X,而且它似乎是随机的或者什么的。ARGGGG。

    只有1 <SPAN & GT; 元素在 <td id="tdcolumn_[row index number]_[column index number]_[layout position number]> 标签,但出于某种原因,它两次调用同一个标签。它应该只叫一次。阿格格我不明白为什么??

    这是我的密码,有人请帮我…

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

    请帮帮我,谢谢:)

    1 回复  |  直到 16 年前
        1
  •  2
  •   Marcel Korpel    16 年前

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