您现在的位置是:首页 > 电脑技术查询 > web开发

jquery each 内部的延时这样写可有用啊解决方法

编辑:chaxungu时间:2022-10-02 23:15:08分类:web开发

jquery each 内部的延时这样写可有用啊?
function postmessage(){
var delayTime = [];

$.each(arr,function(key,val){
//回调函数有两个参数,第一个是元素索引,第二个为当前值
delayTime[key] = setTimeout(function() {
$("#postform").attr("action",val);
$("#postform").attr("target","_blank");
$("#postform").submit();
},2000)

//if (key > 28) return false;

//$.post(val, $("#postform").serialize());
});
}

遍历数组,数组是n个url地址,然后向这些url提交表单

同时提交的太多了,很卡

想做个延时,怎么写啊?

------解决方案--------------------
这样也是掩饰,延时有函数可使用,不要认为的去做一些无谓的操作HTML code<html><head><script src="http://code.jquery.com/jquery-latest.js"></script><script>function show(){ alert("show!!");}$(function(){ $('#mydiv').mouseover(function(){ t = setTimeout("show()",2000); }).mouseout(function(){ clearTimeout(t); });});</script></head><body> <span id="mydiv">我是菜单</span></body>