Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery按类名查找HTML表行_Jquery - Fatal编程技术网

使用jquery按类名查找HTML表行

使用jquery按类名查找HTML表行,jquery,Jquery,在删除任何HTML表的行后,我使用以下代码保留序列号以保留序列号 $("#trid_"+a_href).remove(); $("tr").each(function (index) { if(index != 0) { $(this).find("td:first").html(index + ""); } }); 代码运行正常,但问题是它正在显示表中所有行的序列号。 但我只想在 我的猜测是,为了解决这个问题,我必须在tr中找到class=“product

在删除任何HTML表的行后,我使用以下代码保留序列号以保留序列号

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

 $("tr").each(function (index) {
     if(index != 0) { 
    $(this).find("td:first").html(index + ""); 
    }
});
代码运行正常,但问题是它正在显示表中所有行的序列号。 但我只想在

我的猜测是,为了解决这个问题,我必须在tr中找到
class=“products”
,因此我尝试了以下代码,但这次代码根本不起作用

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

 $(".products tr").each(function (index) {
     if(index != 0) { 
    $(this).find("td:first").html(index + ""); 
    }
});
你能帮我解决这个问题吗。 谢谢

编辑 我的整个代码太大了。所以我上传了剧本


谢谢:)

正确的选择是:

$("tr.products").each ...
“.products tr”
选择所有tr元素,这些元素是具有“products”类的任何节点的后代

“tr.products”
(在
tr
.poducts
之间没有空格)选择具有“products”类别的所有tr节点(这是您在此处想要的)


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

您也可以显示您的HTML代码吗?我想您只需要将其更改为
$('tr.products')。每个(..
但我需要查看要显示的HTMLsure@Ohad,谢谢你的回复。我将通过提供html更新我的答案。谢谢:)@Ohad请检查我问题的编辑部分好吗?谢谢你的回复。我已经尝试了两种
“tr.products”
“tr.products”
但这并不能解决我的问题。你知道问题出在哪里吗?我已经在问题的编辑部分包含了我的其他脚本。你介意看一下吗?谢谢:)
$("tr.products").each(function (index) {
   $(this).find("td:first").html(index); 
});