我下面有这个Javascript

并希望在FireFox中工作
我想在每次提交后保留5秒的延迟

<html>
 <head>
 <script type="text/javascript">
function sleep(ms)
    {
        var dt = new Date();
        dt.setTime(dt.getTime() + ms);
        while (new Date().getTime() < dt.getTime());
    }

function test() {
var windowCounter = 1;
var myStringArray = [ "user1", "user2" , "user3" , "user4" ]
var len = myStringArray.length;
for (var i=0; i<3; ++i) {
document.inform.cid = myStringArray[i];
document.inform.pwd = "xxxxxxxx";
   document.inform.target = windowCounter++; // a different target each time
    document.inform.submit();
}
}
</script>
 </head>
 <body >
  <form name="inform"   target="newWin" action="https://www.google.co.in/">
<input type="text" name="cid"  />
<input type="hidden" name="pwd"  />
 <input type="hidden" name="throttle" value="999" />
    <input type="submit" value="go" onclick="test()">
  </form>
 </body>
</html>


我尝试过在每次提交后手动保持睡眠状态,并尝试使用setTimeOut,但是没有任何效果。

有人可以帮我吗

编辑部分

<html>
<head>
<script type="text/javascript">
  var interval = window.setInterval(iterate, 5000);
var myStringArray = ["user1", "user2", "user3", "user4"];

  function iterate() {
 iterate.arr = iterate.arr || myStringArray.slice(0);

    //if it still has elements left
    if(iterate.arr.length > 0) {
        document.inform.cid = iterate.arr.pop(); //remove the top one
alert(document.inform.cid);
        document.inform.pw = "xxxx";
        document.inform.target = iterate.arr.length; // a different target each time - length of the arr
        document.inform.submit();
    } else {
        window.clearInterval(interval); //no more left cancel it
    }
};

</script>
</head>
<body>
 <form name="inform" method="get"  target="newWin" action="https://www.google.co.in/">
  <input type="text" name="cid" />
<input type="password" name="pw" />
<input type="hidden" name="throttle" value="999" />
    <input type="submit" value="go" onclick="iterate()"/>
  </form>
</body>
</html>

最佳答案

您可以使用类似(未经测试)的方法吗:

    var interval = window.setInterval(iterate, 5000);
    var myStringArray = ["user1", "user2", "user3", "user4"];

function iterate() {
    iterate.arr = iterate.arr || myStringArray.slice(0); //set a private array to cache

    //if it still has elements left
    if(iterate.arr.length > 0) {
    //thought there was more than one formon the page - but if only one then we can reference by its name - cid

        ///:document.inform.cid = iterate.arr.pop(); //remove the top one
    iterate.arr.pop();
        document.inform.pwd = "xxxxxxxx";
        document.inform.target = iterate.arr.length; // a different target each time - length of the arr
        document.inform.submit();
    } else {
        window.clearInterval(interval); //no more left cancel it
    }


};

10-06 11:58