2012-08-22 31 views
0

我試圖通過變量jQuery中jQuery的易變量發出

回調函數,我有:

var test; 

$('.img').hover(function(){ 
    test='this is test'; 

}, function(){ 
    //how do I pass the test value to the callback function..?? 
    console.log(test) 

}) 

感謝您的幫助。

+3

您是否試過運行此代碼? – Blender

+1

演示:(工作正常)http://jsfiddle.net/UsMHW/希望它適合您的需要! –

回答

1

你不需要通過它,你可以在第二個回調函數中訪問test

+0

...因爲變量屬於外部範圍。當然,有'img'類的所有元素共享單個變量。 –

0
var test; 
$('.img').on('hover', function(){ 
test ='this is a test'; 
console.log(test); 
});