2

在删除任何 HTML 表的行后,我正在使用以下代码来保持序列号与序列一致。

 $("#trid_"+a_href).remove();

 $("tr").each(function (index) {
     if(index != 0) { 
    $(this).find("td:first").html(index + ""); 
    }
});

该代码工作正常,但问题是它显示表中所有行的序列号。但我只想显示在<tr class="products">

我的猜测是,要解决这个问题我必须找到class="products"in tr,所以我尝试了以下代码,但这次代码根本不起作用。

$("#trid_"+a_href).remove();

 $(".products tr").each(function (index) {
     if(index != 0) { 
    $(this).find("td:first").html(index + ""); 
    }
});

你能帮我解决这个问题吗?谢谢

编辑

我的整个代码太大了。所以我在这里上传了脚本

谢谢 :)

4

2 回答 2

1

正确的选择器是:

$("tr.products").each ...

".products tr"选择所有 tr 元素,它们是具有“产品”类的任何节点的后代

"tr.products"tr(和之间没有空格.poducts)选择所有具有“产品”类的 tr 节点(这就是你想要的)

"tr .products"将选择所有具有类“.products”的元素,它们是 tr 节点的后代

于 2012-08-29T07:23:55.743 回答
0
$("tr.products").each(function (index) {
   $(this).find("td:first").html(index); 
});
于 2012-08-29T07:24:13.757 回答