0

親ノード ID を完全に表示するのに問題があります。

私はループを使用してテーブル内の div 要素を検出しています。次に、親 TD ノードを見つけて、別の変数でそれから ID を取得しています。

私の問題は、このループ中に、この TD ID を使用して変数を配列内に構築し、印刷すると、最初の文字のみが表示され、2 回目は 2 番目の文字のみが表示され、いつでも表示されることです。その後は空白になります。

変数から配列を削除すると、ID全体が出力されますが、ループが実行されるたびに古い値の名前が最新のものに変更されます。

誰かがこれを理解するのを手伝ってくれますか?

どんな助けでも大歓迎です、前もって感謝します。

Heres 関数 im 書き込み

test.save = function () {

var cell = rd = REDIPS.drag,
    page1a = document.getElementById(redips.p1a),
    divs = TableID.getElementsByTagName('DIV'),
    rd.find_parent('TD', rd.obj),     //parent cell
    st = cell.id,                           //parent cell ID
    st,                     
    id,                                     //div id
    cid,                                   //cell id    
    ccid, 
    concatenator,                         // concatenate oDiv ID
    query = '',
    div,                                // current DIV element
    i;                                  // loop variable

    for (i = 0; i < divs.length; i++) {

    // set current DIV element
    div = divs[i];

    // set current TD ID
    cid = st[i];

    if (div.className.indexOf('drag') > -1) {

                    //takes two characters off of the DIV ID only
        concatenator = div.id.substring(0, div.id.length - 2);

        // creates the query through the loop
            query += cid + '=' + concatenator + ' ';
        }
}

     if (query.length > 0) {
     document.getElementById('message').innerHTML = query;
}
    };

TD ID の配列を使用したバージョンへのリンクはこちら: http://stevenschemers.com/beta1/

TD ID に配列を使用しないバージョンへのリンクを次に示します: http://stevenschemers.com/beta2/

また、「i」は 0、2、4、6、または 1、3、5、7 とカウントアップするため、2 回実行するとループのように見えることにも気付きました。

4

1 に答える 1

0
// loop goes through each DIV element collected on the left side of page 1
for (i = 0; i < divs.length; i++) {
    // set current DIV element
    div = divs[i];

    if (div.className.indexOf('drag') > -1) {
        // sets current cell ID for dropped div
        cid = rd.find_parent('TD', div).id;

        concatenator = div.id.substring(0, div.id.length - 2);
        // creates the query through the loop
            querya += cid + '=' + concatenator + '&';
            qc++;
        }
}
于 2012-05-17T23:32:03.443 に答える