我通過$(document).bind()綁定了頁面的每個元素的事件處理函數。
有沒有人知道如何解除特定元素的處理程序?
這裏是我的示例代碼,不工作的方式我想:這裏考慮到丹尼爾的回答
<html><head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"> </script>
</head>
<body>
<div id="mid" style="cursor:pointer" >click me</div>
<div>sample</div>
<script type="text/javascript">
var fun = function() {
alert('default handler');
};
$(document).bind('click.custom', fun);
//trying to unbind the handler but it remains there
$("#mid").unbind('click.custom');
</script>
</body>
</html>
又是這個問題:
var ff = function() {
alert('additional');
}
$(document).bind('click.custom', fun);
$(document).bind('click.custom2', ff);
$("#mid").bind('click.custom', false);
這裏好玩的事件處理程序是完全綁定的#mid元素,但是ff事件處理程序也沒有綁定,這對我來說是一個問題。
好吧,它很好,謝謝。但是,從處理程序返回false將重置其他名稱空間中的處理程序。有沒有什麼辦法可以解除只綁定特定命名空間的處理程序,並保持其他處理程序不變? – exodus 2011-03-16 00:35:18