[英]onLoad Click Function - RANDOM
Goal: Once the page is loaded a random area on the screen is clicked. 目标:页面加载后,点击屏幕上的随机区域。 Not a certain button or element, just a random click.
不是某个按钮或元素,只是随机点击。
Maybe add an if function that if the click is successful then do another function? 也许添加一个if函数,如果点击成功,那么再做一个函数?
using jquery, an approach can be... 使用jquery,一种方法可以...
var posx = (Math.random() * ($(document).width())).toFixed(); var posy = (Math.random() * ($(document).height())).toFixed(); $('body').append($("<div class=myclass style=left:"+posx+"px;top:"+posy+"px;>Hello from random!</div>")); $( ".myclass" ).click(function() { alert( "random area clicked." ); });
.myclass{ position:absolute; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
What about taking all divs, choosing a random one and click on it? 如何获取所有div,选择一个随机并点击它?
window.onload=function(){
var els=document.getElementsByClassName("*");
els[Math.round((els.length-1)*Math.random())].click();
};
And a click cannot be successful , and you cannot detect that... 点击无法成功 ,你无法检测到......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.