1
我過濾頁面上的元素,然後檢查顯示的項目數,如果少於一定數量,我想使用$ .get()加載更多項目。JQuery - 將'HTMLDivElement'對象數組轉換爲字符串
我正在使用同位素插件,它要求新項目是一個字符串,但我似乎只能得到HTMLDivElement對象。如何將其轉換爲字符串?
var $container = $('#container'),
filters = {};
$container.isotope({
itemSelector: '.element',
});
function loadMoreItems(getQuery) {
var newItems = [];
$.get(getQuery, null, function(data) {
container = $($container, data).eq(0);
if (0 === container.length) {
// incase the element is a root element (body > element),
// try to filter it
container = $(data).filter($container).eq(0);
}
if (container) {
container.find('.element').each(function() {
newItems.push(this);
});
}
alert(newItems); //what to do to get this as a string??
}, 'html');
$container.isotope('insert', newItems, true);
}
感謝您的迴應,但是,我該如何準確地寫出這個?我已經嘗試過各種方法來適應我的代碼,但似乎沒有任何工作。我只需要一個很長的字符串,而不是一個數組。我試圖做this.html()而不是newItems.push(this);但我收到錯誤 – LeeTee
看到更新的答案。 – TigOldBitties