chone
2011-07-23 03:59:41 +08:00
在不需要的触发的时候删除掉handler
var handlerA = function() {alert('a');};
var handlerB = function() {alert('b');};
var btn = $("btn1");
// fire a
btn.bind('click', handlerA);
// fire b
btn.unbind('click', handlerA);
btn.bind('click', handlerB);
或者加一个条件变量,当'click'事件被触发的时候再判断是否执行handler
var fireA = true;
var handlerA = function() {if (!fireA) return; alert('a');};
var handlerB = function() {fi (fireA) return; alert('b');};
// fire handler b
fireA = false;