对于以下每个代码:
$(".landingpage .tableCol-33:nth-child(3) tbody:nth-child(even) tr td").text();
我需要执行以下代码行:
var sub_text = $(".landingpage .tableCol-33:nth-child(3) tbody:nth-child(even) tr td a").text();
var next_text = $(".landingpage .tableCol-33:nth-child(3) tbody:nth-child(even) tr td").text().substring(14, 30);
//full_text.text(full_text.text().replace(sub_text, next_text));
如何在jquery中使用每个?
答案 0 :(得分:1)
尝试使用$.each功能:
var items = $(".landingpage .tableCol-33:nth-child(3) tbody:nth-child(even) tr td")
$.each(items, function(i, val){
var item = $(val);
var sub_text = item.find('a').text();
var next_text = item.text();
})
答案 1 :(得分:0)
$('.landingpage .tableCol-33:nth-child(3) > tbody:nth-child(even) > tr > td').each(function () {
var sub_text = $(this).find('a').text();
var next_text = $(this).text().substring(14, 30);
});
更新: -
$('.landingpage .tableCol-33:nth-child(3) > tbody:nth-child(even) > tr > td').each(function () {
var next_text = $(this).text().substring(14, 30);
$(this).find('a').text("<a>" + next_text + "</a>");
});
更新2: -
获取SubCategory将其包装到ur html中的下面这样的范围中: -
<span class="sub-cat">SubCategory </span>
你可以像以下一样获取它: -
item.find('a').find('.sub-cat').text();