2012-05-28 28 views
0
var currentImageBox;  
$('.newImage').bind('click', function() { 

     currentImageBox = this; 
     currentImageBox.unbind('click'); 
    }); 

我試圖將currentImageBox設置爲被單擊的div(頁面上的多個div具有newImage類)。但無濟於事,我哪裏錯了?獲取jquery中的點擊源?

回答

1

代碼無誤,this是點擊的元素。但要使用unbind,您需要wrap the element with jQuery,因爲this(因此currentImageBox)是DOM元素而不是jQuery對象。

$(currentImageBox).unbind('click'); 
+0

@ user1013512檢查演示,它的工作原理。該代碼從元素中解除綁定,就像代碼一樣。 – Joseph

+0

This is better,currentImageBox = $(this);不過謝謝。 – panthro