2014-09-24 41 views
0

在jquery中,我希望遍歷每個div並顯示其內容。到目前爲止,我已經寫它,我得到錯誤「類型錯誤:無效‘在’操作數」迭代每個div並獲取其html內容

$.each($("div.autocomplete-suggestions > .autocomplete-suggestion").html(), function() { 

    console.log(this); 
}); 

回答

2

您需要遍歷元素,而不是它們的內容。使用方法:

$("div.autocomplete-suggestions > .autocomplete-suggestion").each(function(){ 
    console.log($(this).html()); 
}); 
2

嘗試這個 -

$("div.autocomplete-suggestions > .autocomplete-suggestion").each(function(){ 
console.log($(this).html()); 
})