2012-11-21 46 views

回答

0

您仍然可以通過$(this)訪問它,就像在.click中一樣。

Demo

0

你可以用$(this)訪問它的處理器

$('body').on('click','.class', function() { 
    $(this) or this // This points to the element with .class 
      // which you just clicked 
    alert($(this).attr('class')); // Gets the class name 
}); 
+0

的$(這)會選擇body標籤,不符合的.class標籤的元素。 – user1841175

+0

nope ..它將選擇.class,因爲它已被委託給主體 –

+0

$('body')。on('click',function(){將選擇body,但是$('body')。on ('click','。class',function(){將選擇嵌套在body中的.class –

1

您可以使用this獲取JavaScript對象或$(this)得到jQuery對象內。

$('body').on('click','.class', function() { 
    alert(this.id); //with this, javascript provided properties or methods. 
    alert($(this).attr('id')); // with $(this) jquery provided properties or methods. 
}); 
0

試試這個:

$('body').on('click','.class', function() { 
    $(this).<some property here>; 
});