Click a button every second

2019-01-10 22:23发布

How to click a button every second using JavaScript?

6条回答
ら.Afraid
2楼-- · 2019-01-10 22:46

This will give you some control over the clicking, and looks tidy

<script>
var timeOut = 0;
function onClick(but)
{
    //code
    clearTimeout(timeOut);
    timeOut = setTimeout(function (){onClick(but)},1000);
}
</script>
<button onclick="onClick(this)">Start clicking</button>
查看更多
Evening l夕情丶
3楼-- · 2019-01-10 22:51
document.getElementById('youridhere').click()
查看更多
\"骚年 ilove
4楼-- · 2019-01-10 22:59
setInterval(function () {document.getElementById("myButtonId").click();}, 1000);
查看更多
叼着烟拽天下
5楼-- · 2019-01-10 23:00

this will work ,simple and easy

 `<form method="POST">
<input  type="submit" onclick="myFunction()" class="save" value="send" name="send" id="send" style="width:20%;">
</form>
<script language ="javascript" >
function myFunction() {
setInterval(function() {document.getElementById("send").click();}, 10000);    
}
</script>

`

查看更多
来,给爷笑一个
6楼-- · 2019-01-10 23:03

This would work

setInterval(function(){$("#myButtonId").click();}, 1000);
查看更多
我命由我不由天
7楼-- · 2019-01-10 23:10

You can use

setInterval(function(){ 
    document.getElementById("yourbutton").click();
}, 1000);
查看更多
登录 后发表回答