如何制作一个使用JavaScript的自动点击器,让用户点击屏幕上的随机位置?

huangapple go评论94阅读模式
英文:

How to make a autoclicker that makes the user click on random spots of the screen with javascript?

问题

如何使用JavaScript模拟鼠标点击?如何使它点击屏幕上的随机位置?谢谢帮助!

英文:

I'm making a autoclicker chrome browser extension, but how can I simulate a mouse click using javascript? And how can i make the it click on a random spot of the screen? Thanks for helping!

答案1

得分: 2

只需使用 click() 函数。

document.getElementById('mybutton').click();

如果您想要随机点击,可以使用:

let els = document.querySelectorAll('body *');
var rand = Math.floor(Math.random() * els.length);
els[rand].click();
英文:

Simply by click() function.

document.getElementById('mybutton').click();

If you want a random click use:

let els = document.querySelectorAll('body *');
var rand = Math.floor( Math.random() * els.length );
els[rand].click();

答案2

得分: 1

创建一个带有id和onClick函数的按钮:

<button id="clickMe" onclick="clicked()">点击这里</button>

调用点击函数:

document.getElementById("clickMe").click();

添加此循环以自动执行1000次点击!

for (let i = 0; i < 1000; i++) {
  document.getElementById("clickMe").click();
}
英文:

Create a button with an id & onClick function:

&lt;button id=&quot;clickMe&quot; onclick=&quot;clicked()&quot;&gt;Click Here&lt;/button&gt;

Call the click function:

document.getElementById(&quot;clickMe&quot;).click();

Add this loop to automate 1000 clicks!

for ( let i = 0; i &lt; 1000; i++ ) {
  document.getElementById(&quot;clickMe&quot;).click();
}

huangapple
  • 本文由 发表于 2023年3月8日 17:43:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671444.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定