我有一个 HTML 字符串,是使用 getJSON 方法获取的。我想迭代整个字符串,找到所有带有 product-review
类的 div 并将其内容推送到我的数组中。最好的方法是什么?
最佳答案
第一:您需要使用.find()
选择'div.product-review'
$(response).find('div.product-review')
第二:您需要循环它们并将其内容推送到数组
var contentarray = [];
$(response).find('div.product-review').each(function(){
var ThisIt = $(this);
contentarray.push(ThisIt.text());
});
console.log(contentarray);
关于javascript - Jquery 为每个 HTML 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34471714/