2015-12-26 41 views
2

我有一个HTML字符串,我从使用getJSON方法得到。我想遍历整个字符串,找到类product-review的所有div,并将其内容推送到我的数组中。做这个的最好方式是什么?每个HTML字符串的jquery

+0

也许在网页中有一个隐藏的div,然后将字符串附加到它,并解析它的内容。 –

+0

你可以证明你到目前为止已经尝试过吗? – Will

+0

'$(htmlstring).find('。product-review')'< - 像这样,jQuery解析HTML – adeneo

回答

0

1:您需要使用.find()

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

选择'div.product-review'第二个:你需要通过它们循环并将其内容推向阵列

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

完美地工作 - 非常感谢! – deviant

+0

@deviant欢迎你好运:) –

0

您可以添加字符串转换成一个隐藏的元素,然后找到那个隐藏的元素的所有div

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