1
我有多個分類爲.text的html。我執行.find('。foo')。text()as array
console.log($(whatever).find('.foo').text());
結果是一個包含所有內容的文本字符串。我可以將它保存到一個數組嗎?
我有多個分類爲.text的html。我執行.find('。foo')。text()as array
console.log($(whatever).find('.foo').text());
結果是一個包含所有內容的文本字符串。我可以將它保存到一個數組嗎?
可以使用map
方法來完成這件事
var textArray = $(whatever).find('.foo').map(function() {
return $(this).text();
}).get();
這將讓你的數組。如果你想顯示爲一個字符串,則只需使用join
與它一起。
var arr = [];
$(whatever).find('.foo').each(function() {
arr.push($(this).text());
});