Javascript 如何在单击处理程序中经过一定时间后刷新页面
在我下面的代码/JS中。我只想在点击处理程序启动后(或点击按钮后)刷新页面。。单击触发后大约2或3秒后。因此,基本上点击按钮,2-3秒过去了,然后页面刷新。我想用纯JS,而不是jQuery或使用Javascript 如何在单击处理程序中经过一定时间后刷新页面,javascript,Javascript,在我下面的代码/JS中。我只想在点击处理程序启动后(或点击按钮后)刷新页面。。单击触发后大约2或3秒后。因此,基本上点击按钮,2-3秒过去了,然后页面刷新。我想用纯JS,而不是jQuery或使用 以下是我的JS: $('.download-pdf').click(function() { // I would like to add here notChecked = $("input[type=checkbox]:not(:checked)").parent();
以下是我的JS:
$('.download-pdf').click(function() {
// I would like to add here
notChecked = $("input[type=checkbox]:not(:checked)").parent();
notChecked.hide();
yesChecked = $("input[type=checkbox]:checked").parent();
$.each(yesChecked, function( index, el ) {
$(el).show().html(texts[$(el).attr('id')]);
});
使用setTimeout()
使用setTimeout()
要在2秒后重新加载页面,请使用以下命令
setTimeout(function(){window.location.reload()},2000)代码>要在2秒后重新加载页面,请使用以下命令
setTimeout(function(){window.location.reload()},2000)代码>您可以使用简单的settimeout()
函数将函数延迟一段时间
您可以使用location.reload()代码>要刷新页面,我在更新数据后自己使用它
DelayInMiliconds表示重新加载页面之前所需的秒数。它以毫秒表示,因此为1秒/1000。在这种情况下,你会想把3000
以下是一个例子:
setTimeout(function(){
location.reload();
}, thedelayinmiliseconds);
您可以使用简单的settimeout()
函数将函数延迟一段时间
您可以使用location.reload()代码>要刷新页面,我在更新数据后自己使用它
DelayInMiliconds表示重新加载页面之前所需的秒数。它以毫秒表示,因此为1秒/1000。在这种情况下,你会想把3000
以下是一个例子:
setTimeout(function(){
location.reload();
}, thedelayinmiliseconds);
$('.download-pdf').click(function(event) {
//remove default click behavior
event.preventDefault();
//refresh page after 3 seconds
setTimout( 'window.location.reload()', 3000);
notChecked = $("input[type=checkbox]:not(:checked)").parent();
notChecked.hide();
yesChecked = $("input[type=checkbox]:checked").parent();
$.each(yesChecked, function( index, el ) {
$(el).show().html(texts[$(el).attr('id')]);
});
}