あなたはフラグを設定し、それが再結合し、イベントハンドラ、その後foo()
機能を実行したり、イベントをバインド解除は、ユーザーがそれを使用することができるようにしたくない時間とするOKだかどうかを確認することができます遅延の後(ちょうどカップルオプション)。
ここで私は何をしますか。しかし、3グーグルの時間と試行錯誤した後、これは御馳走を作品、
$(document).delegate('#my-page-id', 'pageinit', function() {
//setup a flag to determine if it's OK to run the event handler
var okFlag = true;
//bind event handler to the element in question for the `click` event
$('#my-button-id').bind('click', function() {
//check to see if the flag is set to `true`, do nothing if it's not
if (okFlag) {
//set the flag to `false` so the event handler will be disabled until the timeout resolves
okFlag = false;
//set a timeout to set the flag back to `true` which enables the event handler once again
//you can change the delay for the timeout to whatever you may need, note that units are in milliseconds
setTimeout(function() {
okFlag = true;
}, 300);
//and now, finally, run your original event handler
foo();
}
});
});
私は追跡変数を使用していない言及した元の質問を知っている:私は、その後のイベントを除外するために、タイムアウトを使用します!私の+1。 –
別の変数にない場合は、フラグ変数をjQueryデータとして保存することもできます。 '$ .data(これ、 'フラグ'、[状態])' – Jasper