你的html有一些问题,而你的jQuery一开始就像SKS所说的那样,你的html文档中不能有多个具有相同ID的节点. ID必须是唯一的.我推荐使用一个类.
您还应该在< thead>中添加标题行和< tbody>中的表格正文
现在,在您的jQuery上,$(“td”)将找到文档中的所有td,而不仅仅是行中的td.
你会想要使用
$(this).find(‘td’)或者您可以使用.children或更高级别的选择器.有许多不同的,正确的方法来获取此信息.
我已经采用你的代码并修改它:
$("tbody").find("tr").each(function() { //get all rows in table
var ratingTdText = $(this).find('td.Rating').text();
//gets the text out of the rating td for this row
alert(ratingTdText);
});
这适用于稍微修改的html:
CoffeeID Degree Weight Profile UsageInfo Comments AmbientTemp Rating WeightDeducted Selected ProfileID ProfileStart
1 1 3 9 Filter Brew Perfecto!! 55 4.25 1 4 34 1 3 15 99 87 Espresso WTF 99 4.5 5 3 66 4希望这有助于您朝着正确的方向前进!
哦,我差点忘了!这里是一个jsfiddle的链接,所以你可以看到这个在行动:http://jsfiddle.net/fCpc6/