我想为按钮添加去抖动功能,但我想在每次用户单击按钮时执行一些操作,但仅在用户单击按钮后 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));