2012-05-11 38 views
0

我有一些問題,獲取父節點ID以顯示整體。我使用一個循環來檢測表格中的div元素,然後我找到它的父TD節點,並在另一個變量中獲得id的關閉。查找父('TD')ID循環不顯示整個ID

我的問題是,在這個循環中,我用這個TD ID在數組裏面建立一個變量,當它打印時,第一次只顯示第一個字符,然後第二次只顯示第二個性格,隨後的任何時候都會變成空白。

如果我從變量中刪除數組,它將打印整個ID,但它會在每次循環運行時將舊值重命名爲最近的值。

有人可以幫我解決這個問題嗎?

任何幫助表示讚賞,在此先感謝。

下面有功能即時通訊使用與所述TD ID的數組書面方式

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

繼承人到版本的鏈接:http://stevenschemers.com/beta1/

和繼承人不使用用於TD ID陣列以一個版本的鏈接:http://stevenschemers.com/beta2/

我還注意到,這似乎是循環運行如果兩次,因爲 'I' 將計數0,2,4,6,或有時1,3,5,7

+0

什麼是'divs'?什麼是「rd」?文件的結構是什麼?你是什​​麼意思,從變量中刪除箭頭? – Amadan

+0

對不起,我的數組。 rd涉及到ajax中的拖放功能。 Divs獲得表格內的div。當完整顯示div id時,Concatenator變量完美工作,但沒有cid – xxstevenxo

+0

我更新了我的代碼供您查看 – xxstevenxo

回答

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