jquery prevent duplicate function assigned
问题 If I need to assign a click function dynamically, is there a way to ensure the click function is only assigned once and not duplicated? this.click(function(){ alert('test'); }) 回答1: You can unbind the click event before you bind it again, that way you will only have one event attached to it: //assuming this is a jquery object. this.unbind("click"); this.click(function(){ alert("clicked once"); }); As of jQuery 1.7, click now uses .on (http://api.jquery.com/click/) so the correct code is now /