2011-07-21 160 views

回答

5

这里做的一种方式

$("#test").click(function() { alert('hello'); return false; }); 
// Before the last event handler. 
$("#test").unbind("click"); 
$("#test").click(function() { alert('world'); return false; }); 
4

您可以使用jQuery one()

$("#tesr").one("click", function() { 
    alert("This will be displayed only once."); 
}); 

小提琴这里:http://jsfiddle.net/ms2RP/1/

+0

你的答案是无关的question..and可能会混淆谁到这里来的人。 – vsync

5

您可以取消绑定先前的事件处理程序和附加只有一个你想要的。

element.unbind(event).bind(event,eventHandler);