使按钮本身点击 [英] Make a button click itself

查看:89
本文介绍了使按钮本身点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想制作一个脚本,所以可以将脚本粘贴到f12开发人员控制台中,并且具有特定ID的按钮将单击自身10次。

I just want to make so I can paste the script into the f12 dev console and the button with specific id is going to click itself 10 times.

推荐答案

您可以使用普通的JavaScript来实现此目标,例如:

You can achieve this using plain JavaScript like this:


  • 您可以使用setTimeout()让您有时间将代码段粘贴到控制台中。

  • 之后,您可以使用setInterval()来执行按钮单击指定的间隔。(您需要清除间隔以使其停止执行)。

  • 您使用document.getElementById( button-id)。click()单击按钮。

我们将所有内容合并为一个片段:

Lets combine all of this in a snippet:

setTimeout(function() {
    var counter = 0;
    var interval = setInterval(function(){
         document.getElementById("button-id").click(); // Clicks the button
         counter++; // Increases counter after every click
         if(counter == 10) clearInterval(interval); // Stops after 10 clicks
    },1000); // Will click the button every second
}, 10000) // Starts after 10 seconds

希望对您有所帮助:)

这篇关于使按钮本身点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆