可能重複:
How to check if jQuery object exist in array?的jquery inArray()
有任何方法,以確定是否一個DOM元素是在DOM元素的數組?
即
$(".container img").each(function(){
views.push($(this).clone());
});
創建克隆圖像元素的陣列。我現在想檢查一個新的圖像元素是否在該數組中?
感謝
可能重複:
How to check if jQuery object exist in array?的jquery inArray()
有任何方法,以確定是否一個DOM元素是在DOM元素的數組?
即
$(".container img").each(function(){
views.push($(this).clone());
});
創建克隆圖像元素的陣列。我現在想檢查一個新的圖像元素是否在該數組中?
感謝
$(".container img").each(function(){
if(jQuery.inArray($(this), views) === -1)
{
views.push($(this).clone());
}
});
'views.indexOf(yourImage)!== -1' –
你不喜歡['inArray()'](http://api.jquery.com/ jQuery.inArray /)?你已經寫在標題... – Christoph