2013-03-12 96 views

回答

2

嘗試以下操作:

$(this).find('img').remove(); 

Here's the updated Fiddle

+0

好的謝謝。但根據[jQuery API](http://api.jquery.com/remove/),我的版本應該可以工作。你明白爲什麼它不? – Maxbester 2013-03-12 08:59:11

+0

這當然是一個奇怪的行爲,它似乎'remove()'運行正常,但是[這個bug報告](http://bugs.jquery.com/ticket/7816)顯示它很混亂。 – 2013-03-12 09:02:44

+2

@Maxbester,你錯誤地解釋了文檔。從文檔'$('div')。remove('。hello');意味着刪除具有'.hello'的'div'。該參數充當'filter'(而不是'selector')。你的代碼'$(this).remove('img');'表示從'$(this)'的數組中,過濾具有'img'標籤的元素並且只刪除它。 – Jashwant 2013-03-12 09:03:54