gpt4 book ai didi

javascript - 我怎么能找到特定 TD 中的文本,其中包含 TR 存储为这个的 css 类

转载 作者:行者123 更新时间:2023-11-30 12:48:22 24 4
gpt4 key购买 nike

我使用这段代码来遍历 tr

 $('#prod_tbl > tbody  > tr').each(function () {
var x = $(this);

});

现在我想要的是我有不同类名的 TD,比如 .price,.name

当我循环遍历 TR 时,我想访问不同变量中每个 TD 的值

喜欢

     $('#prod_tbl > tbody  > tr').each(function () {
var x = $(this);
var price=$("td.price").text();
var name= $("td.name").text();


});

对于每个TR

最佳答案

您必须在此上下文中使用 .find() 来完成您的任务。那是因为 td 是每个 Tr 的后代。 $(this) 将指向 Tr,所以我们必须使用 .find(selector) 来找到它的匹配后代,

尝试,

 $('#prod_tbl > tbody  > tr').each(function () {
var x = $(this);
var price= x.find("td.price").text();
var name = x.find("td.name").text();
});

请阅读here了解更多关于 .find()

的信息

关于javascript - 我怎么能找到特定 TD 中的文本,其中包含 TR 存储为这个的 css 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21825845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com