0

わかりました、これは一晩中私を殺してきました、つまり私はこのコードに少なくとも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]が、一部の神は理由を知っているため、問題が発生します。同じタグを2回更新し<span>ます。これにより、目的の値から必要以上に1に変更されます...各の1 <span>内にはタグのみがあります。なぜ1つだけ2倍に設定されているのかわかりませんが、ランダムか何かのようです。argggg。firstChild <td> element<tr> elements

<span>タグには要素が1つしかありません<td id="tdcolumn_[row index number]_[column index number]_[layout position number]>が、何らかの理由で、同じタグを2回呼び出しています。一度だけ呼び出す必要があります。arggg。なんで分からないの?

これが私のコードです誰かがここで私を助けてください...

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

私を助けてください、ありがとう:)

4

1 に答える 1

2

関連するHTMLパーツがないと問題を解決できないと思いますが、コードに少なくとも1つのエラーがあります。

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、要素のを設定します)。

于 2010-05-23T11:08:56.907 に答える