Jquery 对于 HTML 字符串中的每个

Jquery for each in HTML string

我有一个 HTML 字符串,它是我使用 getJSON 方法得到的。我想遍历整个字符串,找到所有带有 class product-review 的 div,并将其内容推送到我的数组。最好的方法是什么?

您可以将该字符串添加到隐藏元素中,然后在该隐藏元素中找到所有 div

var YOUR_CONTENT=$(".hiddelElement div.product-review").text();

1st : 您需要使用 .find()

select 'div.product-review'
$(response).find('div.product-review')

2nd: 你需要遍历它们并将其内容推送到数组

var contentarray = [];
$(response).find('div.product-review').each(function(){
    var ThisIt = $(this);
    contentarray.push(ThisIt.text());
});
console.log(contentarray);