且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery从td单元格获取文本

更新时间:2022-11-02 23:18:43

首先总之,你的选择器是矫枉过正的。我建议使用类或ID选择器,如下面的示例。一旦你纠正了你的选择器,只需使用jQuery的 .each()来迭代你的选择:

First of all, your selector is overkill. I suggest using a class or ID selector like my example below. Once you've corrected your selector, simply use jQuery's .each() to iterate through the collection:

ID选择器:

$('#mytable td').each(function() {
    var cellText = $(this).html();    
});

班级选择器:

$('.myTableClass td').each(function() {
    var cellText = $(this).html();    
});

附加信息:

查看 jQuery的选择器文档