如何使用 JavaScript 自动单击浏览器按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4515944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 12:45:14 来源:igfitidea点击:
How to click a browser button with JavaScript automatically?
提问by 001
How to click a button every second using JavaScript?
如何使用 JavaScript 每秒单击一个按钮?
回答by John Hartsock
setInterval(function () {document.getElementById("myButtonId").click();}, 1000);
回答by Isaac
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>
回答by KonaRin
document.getElementById('youridhere').click()
回答by Meuru
This would work
这会工作
setInterval(function(){$("#myButtonId").click();}, 1000);
回答by Footer
You can use
您可以使用
setInterval(function(){
document.getElementById("yourbutton").click();
}, 1000);
回答by nikunj
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>
`
`