我需要一个每3秒钟点击该按钮的脚本。
<input type="submit" name="Submit" value="Puxar Alavanca">
<input type="submit" name="Submit" value="Puxar Alavanca">
<input type="submit" name="Submit" id="but" value="Puxar Alavanca">
var but = document.querySelector("[name='Submit']");
setInterval(function () {but.click();},3000);
Try using setInterval() method
.document.querySelector()
selects your element,the setInterval() clicks
button on every 3 seconds and the click event is handled by a function
.
var btn = document.querySelector("[name='Submit']");
//console.log(btn);
setInterval(function(){
btn.click();
},3000);
//Handling of click event
btn.onclick=function(){
console.log('clicked');
}
<input type="submit" name="Submit" value="Puxar Alavanca">
setInterval(function(){
$( "input" ).trigger("click");
},random(3000,4000));
function random(min,max){
return min + (max - min) * Math.random()
}
由于您没有类名等内容,因此在执行此操作时,请确保仅单击所需的按钮。
使用我的版本,它允许收集所有类型为“input”的标签,并且只能点击您请求的一个 - 每3-4秒(此数字是随机生成的,有时是3,有时是4)。
请参见下文:
// Random time between 3 and 4 seconds.
var randomTime = (Math.floor(Math.random() * (4 - 3 + 1)) + 3) * 1000;
setInterval(function() {
var tags = document.getElementsByTagName("input");
for (var i = 0; i < tags.length; i++) {
if (tags[i].value == "Puxar Alavanca") {
tags[i].click();
// Below alert should be removed, just for testing/showing purposes.
alert("Button clicked after " + randomTime + "ms.");
}
}
}, randomTime);
<input type="submit" name="Submit" value="Puxar Alavanca">
setInterval
。 - Carcigenicate