可能重複:
How can I remove the event handler once the click event has fired?如何讓按鈕可以點擊一次?
我試圖使用實時點擊事件指派給一個按鈕,希望用戶只能觸發它只有一次。有沒有辦法做到這一點?
//I only want the alert show once and disable the click event...
$('#testBtn').live('click', function(){
alert('hey ya');
})
請注意:按鈕是動態創建的。
請看這個http://api.jquery.com/one/ –
請更新您的問題,清楚地表明您正在使用,因爲元素是動態創建的。 – Archer
我已經在這裏爲您測試了哪些測試用例最快 - http://jsperf.com/one-event –