2011-07-04 91 views
2

我想用Jquery淡出表格中的所有圖像。用Jquery褪去所有圖像

以下似乎不起作用。可能是語法錯誤?

$(function() { 
    $('#myTable img').each(function(index) { 
     $(this).fadeOut('slow', function() { 
    // Animation complete. 
     }); 
    }); 
}); 
+0

適合我。也許你的ID是錯的:http://jsfiddle.net/jomanlk/y9zCK/ – JohnP

+0

我有一個錯誤之上。謝謝它的工作 – james

回答

1

你只需要做到這一點:

$(function() { 
    $('#myTable img').fadeOut('slow', function() { 
     // Animation complete. 
     }); 
}); 

您不必使用each方法。

如果你想使用each方法,請執行下列操作

$(function() { 
    $('#myTable img').each(function(index,e) { 
     $(e).fadeOut('slow', function() { 
     // Animation complete. 
     }); 
    }); 
}); 

e將引用當前圖像。

+0

我需要使用每個原因,我必須有每個圖像的參考?謝謝 – james

+0

好的,我編輯了我的回答。請讓我知道它是否適合你。 –

+0

@marc這並不能解釋他爲什麼當前的代碼有效。另外$(this)會引用圖片,不是嗎? – JohnP