需要准备的材料分别有:电脑、html编辑器、浏览器。
1、首先,打开html编辑器,新建html文件,例如:index.html,并引入jquery。
2、在index.html中的<script>标签,输入jquery代码:
$('tr').each(function () {
$(this).find('td').each(function (i) {
if (i !== $(this).parent().find('td').length - 1) {
$('body').append($(this).text());
}
});
});
3、浏览器运行index.html页面,此时成功获取了表格除最后一列外的所有单元格的数据并打印了出来。
应该没有一次性,历遍每一行,然后如果是最后一个td不要。
var $tds=$();