[英]jQuery unbind events declared in scope
我有一些對象會創建附加到document的事件 。 它們是常見事件,例如mousemove,mousedown等。
然后,我想使$(document).unbind('mousemove')
及其確定,但它可能會使插件的最終用戶創建的某些事件崩潰或導致與某些外部代碼沖突 。
是否可以僅刪除在某個范圍內聲明的所有事件 ?
喜歡:
$.fn.somePlugin = function() {
//here begins our scope
//declaring a lot of events
//some stuff
//remove events of this scope leaving other of same type untouched
}
還是有其他方法可以管理事件組?
將對函數的引用傳遞給off
方法。
var foo = function() {
// Code to handle some kind of event
};
// ... Now foo will be called when paragraphs are clicked ...
$( "body" ).on( "click", "p", foo );
// ... Foo will no longer be called.
$( "body" ).off( "click", "p", foo );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.