如何为javascript日期对象timeObject添加10秒.我认为这样的事情......
var timeObject = new Date()
var seconds = timeObject.getSeconds() + 10;
timeObject = timeObject + seconds;
Run Code Online (Sandbox Code Playgroud) 我想为一个按钮添加一个debounce,但是我希望每次用户点击按钮时执行一些操作,但只有在用户点击按钮后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
}
Run Code Online (Sandbox Code Playgroud)
$('input').bind('keyup blur', $.debounce(process, 5000));
Run Code Online (Sandbox Code Playgroud)