2010-07-29 49 views
2

我想從所有的標籤中解除事件處理程序(點擊),並以某種方式它不工作。你們知道爲什麼嗎?刪除兒童的事件處理程序

// Remove eventhandlers 
    row.find('a').each(function(){ 
     $(this).unbind('click'); 
     alert($(this).attr("onClick")); 
    }); 

它會一直輸出當前的onClick函數。

感謝

回答

4

jQuery的.unbind()就解除jQuery的分配和維護處理。您的內聯處理程序不受影響。

如果要刪除內聯屬性,請使用removeAttr()

row.find('a').each(function(){ 
    $(this).removeAttr('onClick'); 
    alert($(this).attr("onClick")); 
}); 

http://api.jquery.com/removeattr/

+0

非常感謝你! – Kel 2010-07-29 14:16:16

+0

@凱爾 - 不客氣。 :O) – user113716 2010-07-29 14:25:47

0
$('a').unbind('click'); 

$('a').each(function() { 
    return false; 
});