2012-12-07 66 views

回答

1

要獲得通過索引特定的細胞,可以使用:

$(this).children(":eq(1)") 

爲了得到第10個孩子,用途:

$(this).children(":lt(10)") 

如果你想在單獨的細胞中的內容一個數組,你可以做

var texts = $(this).children(":lt(10)").map(function(){return $(this).text()}); 

這使得數組是這樣的:

通過所有的 td小號
["contentofcell1", "cell2", "3", "cell 4", "five", "six", "sieben", "otto", "neuf", "X"] 
+0

這是神奇的代碼,我一直在尋找。非常感謝! $(本)。兒童( 「:EQ(1)」)。文本(); – Giuseppe

1
$(this).children("td").each(function() { 
    alert($(this).text()); 
} 

將循環。

1

試試這個

$("#existcustomers tr").click(function() { 
    var td1 = ""; 
    // To get values of td's between 2 and 10 we should search for 
    // the td's greater than 1 and less than 11... 
    $.each($(this).children("td:lt(11):gt(1)"),function() { 
     td1 += $(this).text(); 
    }); 
    alert(td1); 
}); 
2

使用eq(index)輕鬆找到它。

$("#existcustomers tr").click(function() { 
    var td1 = $(this).children("td").first().text(); 
    var td2 = $(this).find("td").eq(2).text(); 
    var td10 = $(this).find("td").eq(10).text(); 
    alert(td1 + "-" + td2 + "-" + td10); 
}); 

得到TD2的價值觀 - TD10範圍:

$("#existcustomers tr").click(function() { 
    var td1 = $(this).children("td").first().text(); 
    var result = ""; 
    for(var i=2; i<=10; i++) { 
     result = result + " - " + $(this).find("td").eq(i).text(); 
    } 
    alert(td1 + result); 
}); 
相關問題