好吧,我試圖去處理JS中的nextSibling函數。這是我的問題在下面的代碼...nextSibling問題,應該很簡單
var fromRow = document.getElementById("row_1");
while(fromRow.nodeType == 1 && fromRow.nextSibling != null)
{
var fRowId = fromRow.id;
if (!fRowId) continue;
// THIS ONLY gets done once and alerts "row_1" ONLY :(
alert(fRowId);
fromRow = fromRow.nextSibling;
}
好吧有人能告訴我這個代碼有什麼問題嗎?這個document.getElementById("row_1");
元素旁邊有兄弟姐妹,因爲我可以看到它們,它們都具有id屬性,所以爲什麼它沒有得到兄弟姐妹的id屬性?我不明白。
row_1
是TR
元素,我需要得到這個表中的TR
元素在它旁邊,但由於某些原因,它只是變得我已經可以使用document.getElementById
,arggg拿到1元。
謝謝你們:)
謝謝你,這工作了魅力:) – SoLoGHoST 2010-05-24 22:16:38
@SoLoGHoST:樂意幫助:-) – 2010-05-24 22:18:40