2013-03-14 50 views
-5

如何通過單擊圖像執行以下代碼?添加代碼以單擊事件

$('#container').animate({'opacity': 0}, 1000, function() { 
$(this).text('new text'); 
}).animate({'opacity': 1}, 1000); 
+3

通過'$(圖像)。在包裹它(「點擊」,函數(){'也許 – 2013-03-14 16:38:35

回答

6
$('yourimageselector').click(function() { 
    $('#container').animate({ 
     'opacity': 0 
    }, 1000, function() { 
     $(this).text('new text'); 
    }).animate({ 
     'opacity': 1 
    }, 1000); 
}); 
+1

我想通了,回來回答自己,但你打我吧。我知道這是一個簡單的問題,但我正在學習,並且非常感謝你抽出時間! – Chrismo16 2013-03-14 16:43:07

+1

@ Chrismo16在問之前請花一些時間來嘗試它,因爲這是改善自己的最佳方式 – Eli 2013-03-14 16:44:35

+0

同意。我一直試圖在很短的時間內解決問題,而且我的大腦處於信息超載狀態。 – Chrismo16 2013-03-14 16:48:35