// here i store my var $(window).scroll(function(){ myScroll = $(window).scrollTop() }); $("#itemUnbind").click(function(){ // here i need to remove the listener }); $("#itemBind").click(function(){ // here i need to add listener again });
谢谢。
off
var scrollHandler = function(){ myScroll = $(window).scrollTop(); } $("#itemBind").click(function(){ $(window).scroll(scrollHandler); }).click(); // .click() will execute this handler immediately $("#itemUnbind").click(function(){ $(window).off("scroll",scrollHandler); });