自定義JavaScript的 Sleep 函數
//sleep函數
var sleep = (function(){
var queue = [],
isFree = true;
return function(fn, delay){
var args = arguments,
self = this;
if(isFree){
isFree = false;
setTimeout(function(){
fn();
isFree = true;
if(queue.length !== 0){
args.callee.apply(self, queue.shift());
}
}, delay);
}else{
queue.push(args);
}
}
})();
// 測試
var card = document.getElementById('a_magic_visit');
for(var i = 0; i < 100; i=i+1){
try{
sleep(function(){
card.click()
},2000);
sleep(function(){
ajaxpost('magicuse_form_visit')
},2000);
sleep(function(){
hideMenu()
},2000);
} catch(e){}
}</pre>
本文由用戶 灬猜想灬 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!