简体   繁体   English

是否可以在不单击按钮的情况下设置计时器?

[英]Is it possible to set a timer without clicking on the button?

How do i set Automatic timer on a button after 5 seconds (html) 5秒后如何在按钮上设置自动计时器(html)

Below is the code: 下面是代码:

<INPUT TYPE="button" onClick="history.go(0)" VALUE="Refresh Page" style="font-size:100%""font-family:'Orator Std';" />

Emulate user click with JavaScript: 使用JavaScript模拟用户点击:

var click = setTimeout(function(){
    var button = document.getElementById('your-button-id');
    if (button) {
        button.click();
    }
}, 5000);

Add directly to the button with this: 使用以下命令直接添加到按钮:

onclick="setTimeout(function(){history.go(0);}, 5000);"

JavaScript only: 仅JavaScript:

var history = setTimeout(function(){
    history.go(0);
}, 5000);

But why use history.go(0); 但是为什么要使用history.go(0); ? If you want to reload the page, use this: 如果要重新加载页面,请使用以下命令:

var reload = setTimeout(function(){
    document.location.reload();
}, 5000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM