ボタンにデバウンスを追加したいのですが、ユーザーがボタンをクリックするたびにいくつかのアクションを実行したいのですが、ユーザーがボタンを押してから 5 秒後にのみ SQL 更新を実行します。通常、スロットルはリスナーに直接適用されるようです。ここでは、ボタンがクリックされるたびにいくつかのアクションを実行し、妥当な待機期間の後に更新を行います。
この場合の関数の使い方がわかりません...
参照: http://code.google.com/p/jquery-debounce/
$('#myButton').click(function() {
// do a date calculation
// show user changes to screen
// wait until user has has stopped clicking the
// button for 5 seconds, then update file with "process" function.
});
function process(){
// update database table
}
デバウンス構文
$('input').bind('keyup blur', $.debounce(process, 5000));