关于setTimeout在GM

来源:互联网 发布:淘宝代码需要修改热点 编辑:程序博客网 时间:2024/04/20 11:30
Question:
0 down vote favorite

I've tried to develop a simple Greasemonkey script in javascript. How can I automatically simulate a click on specific button with an interval between each click?

Here's my code:

var Next=document.getElementsByClassName("SubmitButton");for (var i=0, c = Next.length; i<c; i++){    Next[i].click();    setTimeout('Next[i].click()',3000);}

The problem is that the code only clicks on the first value of Next. Why?




Answer:

var Next = document.getElementsByClassName("SubmitButton");for (var i = 0, c = Next.length; i < c; i++) {//Next[i].click();  (function(element, time){    setTimeout(function(){ element.click(); }, time);  })(Next[i], 3000 * i);}

原创粉丝点击