急!在线等!有没有延时函数setTimeout不好用 setTimeout(alert(1),3000)setTimeout(alert(2),3000)trysetTimeout('alert(1)',3000)setTimeout(function () { alert(2) },3000); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 setInterval我也试过了,不过setInterval的函数参数不能变化呀,不能老执行那一个参数,我参数是要变化的,就没有像什么Wait之类的?? 说白了我就想执行re_pic(1)过3秒后执行re_pic(2)过3秒后执行re_pic(3)过3秒后执行re_pic(4)过3秒后执行re_pic(52)过3秒后执行re_pic(6)过3秒后执行re_pic(7)过3秒后执行re_pic(8)过3秒后执行回re_pic(1) 你加个if else 不就可以了? if(x == 9) { x=1; setInterval(...)}else { setInterval(...)} <script type="text/javascript">var args = [1, 2, 3, 4, 5, 6, 7];var exec = function () { alert(Array.prototype.slice.call(arguments, 0).join('\n')); if (args[0] === args.pop()) window.clearInterval(timer);};var timer = window.setInterval(function () { exec.apply(null, args);}, 100);</script>- -我还以为你想要这样的呢.不过按照你那样说,你从exec里控制当前位置不就行了?为什么非要传递的参数不一样? 你可以参考这个.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>轻量封装图片轮动</title><script lanuage="javascript">var ImgConvert = function (imgid, linkid) {//构造参数 this.imgid = imgid; this.linkid = linkid; this.cursor = 0; this.imgs = [];};ImgConvert.prototype = { constructor : ImgConvert , add : function (src, href) { //缓存图片 return (this.imgs[this.imgs.length] = { obj : new Image, "href" : href }).obj.src = src; } , convert : function () { //变化 var obj = this.imgs[this.cursor = this.cursor + 1 < this.imgs.length ? this.cursor + 1 : 0] , img = document.getElementById(this.imgid); if ('undefined' !== typeof img.style.filter) { //如果不支持,就不用滤镜 img.style.filter = "blendTrans", img.filters(0).apply(), img.filters(0).play(); } img.src = obj.obj.src, document.getElementById(this.linkid).href = obj.href; } , load : function () { //初始化成员 var img = document.getElementById(this.imgid), i = 0, a = Array.prototype.slice.call(arguments, 0), t; for (; i < a.length ; i ++) { t = a[i].split('|'), this.add(t[0], t[1]); } } };var wc = new ImgConvert('img', 'link');wc.load( 'http://www.google.cn/intl/zh-CN/images/logo_cn.gif|http://www.google.com/' , 'http://www.baidu.com/img/logo.gif|http://www.baidu.com/' , 'http://www.csdn.net/images/newcsdnlogo.gif|http://www.csdn.net/');window.onload = function () { window.setInterval(function () { wc.convert(); }, 3000); };</script></head><body><a id="link" href="http://www.google.com/" target="_blank"> <img id="img" src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" border="0" alt="" /></a></body></html> 楼上的没听明白我的意思,现在不是循环的问题,是如果我这样写那些函数不是每隔3秒执行一次,而是几乎同时响应我就想要一个函数,能延时几秒,之后再执行下一条re_pic()函数 闭包的典型应用: function Timer(Pars) { function doTimer() { alert(Pars); } return doTimer; } var t =Timer('值'); setInterval(t,2000); function lay(arg){ if (arg > 3){ arg = 0; } alert(lay); setTimeout(function(){lay(arg + 1);},3000)} 天啊,没一个让我满意的,我就想要一个真正能实现延时几秒钟执行下一条语句的方法都没有alert(1);alert(2);中间加什么能让这两个窗口弹出时间间隔5秒 alert(1) 和 alert(2) 是两个不同的进程?各自循环?你都没说明白需求如果只是一次的话setTimeout(function(){alert(1);setTimeout(function(){alert(2)},3000);},3000) function lay(arg){ arg ++; if (arg > 8){ arg = 1; } re_pic(arg); setTimeout(function(){lay(arg);},3000)}lay(0); 我终于在下班前自己想出答案了,和楼上的仁兄基本一样,这才是我想要的答案,需求没说清楚多多见谅.<html><head><SCRIPT LANGUAGE="JavaScript">var i=0;function go_to_re(){setTimeout("go_to_re()",2000);i++;if (i==9) i=1;re_pic(i);}</SCRIPT></head><body onload="go_to_re()"></body></html>其实就这很简单,多谢楼上的哥哥费心了,不过还是要给你分,楼上哥哥看上去是个好人 javascript 参数传递的问题 ui 对于append()的新元素,drop不能放入 求高手帮助解决页面定位问题---------急!!!! 求qq邮箱的一个功能 淘宝网 鼠标随图片效果 ??? js获取多个下拉列表的value求和并输出到一个文本域中,应该怎么实现? html页面文章在粘贴的时候怎么保持原来的格式呢? document.body.innerText显示问题 我想在TD单击时弹出一个位于td下边宽度与td相同的Div,这要怎么做? 后台返回的数据前台是怎么去的三个字段的值? 求js方法,高手进哦! 如何替换下面的字符串,谢谢大家
re_pic(1)过3秒后执行
re_pic(2)过3秒后执行
re_pic(3)过3秒后执行
re_pic(4)过3秒后执行
re_pic(52)过3秒后执行
re_pic(6)过3秒后执行
re_pic(7)过3秒后执行
re_pic(8)过3秒后执行回re_pic(1)
x=1;
setInterval(...)
}else {
setInterval(...)
}
var args = [1, 2, 3, 4, 5, 6, 7];var exec = function () {
alert(Array.prototype.slice.call(arguments, 0).join('\n'));
if (args[0] === args.pop()) window.clearInterval(timer);
};var timer = window.setInterval(function () {
exec.apply(null, args);
}, 100);
</script>- -
我还以为你想要这样的呢.
不过按照你那样说,你从exec里控制当前位置不就行了?
为什么非要传递的参数不一样?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>轻量封装图片轮动</title>
<script lanuage="javascript">
var ImgConvert = function (imgid, linkid) {
//构造参数
this.imgid = imgid;
this.linkid = linkid;
this.cursor = 0;
this.imgs = [];
};ImgConvert.prototype = { constructor : ImgConvert
, add : function (src, href) {
//缓存图片
return (this.imgs[this.imgs.length] = { obj : new Image, "href" : href }).obj.src = src;
}
, convert : function () {
//变化
var obj = this.imgs[this.cursor = this.cursor + 1 < this.imgs.length ? this.cursor + 1 : 0]
, img = document.getElementById(this.imgid);
if ('undefined' !== typeof img.style.filter) {
//如果不支持,就不用滤镜
img.style.filter = "blendTrans", img.filters(0).apply(), img.filters(0).play();
}
img.src = obj.obj.src, document.getElementById(this.linkid).href = obj.href;
}
, load : function () {
//初始化成员
var img = document.getElementById(this.imgid), i = 0, a = Array.prototype.slice.call(arguments, 0), t;
for (; i < a.length ; i ++) { t = a[i].split('|'), this.add(t[0], t[1]); }
}
};var wc = new ImgConvert('img', 'link');
wc.load(
'http://www.google.cn/intl/zh-CN/images/logo_cn.gif|http://www.google.com/'
, 'http://www.baidu.com/img/logo.gif|http://www.baidu.com/'
, 'http://www.csdn.net/images/newcsdnlogo.gif|http://www.csdn.net/'
);
window.onload = function () { window.setInterval(function () { wc.convert(); }, 3000); };
</script>
</head>
<body>
<a id="link" href="http://www.google.com/" target="_blank">
<img id="img" src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" border="0" alt="" />
</a>
</body>
</html>
我就想要一个函数,能延时几秒,之后再执行下一条re_pic()函数
{
function doTimer()
{
alert(Pars);
}
return doTimer;
}
var t =Timer('值'); setInterval(t,2000);
if (arg > 3){
arg = 0;
}
alert(lay);
setTimeout(function(){lay(arg + 1);},3000)
}
alert(1);alert(2);
中间加什么能让这两个窗口弹出时间间隔5秒
function lay(arg){
arg ++;
if (arg > 8){
arg = 1;
}
re_pic(arg);
setTimeout(function(){lay(arg);},3000)
}lay(0);
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var i=0;
function go_to_re()
{
setTimeout("go_to_re()",2000);
i++;
if (i==9) i=1;
re_pic(i);
}
</SCRIPT>
</head>
<body onload="go_to_re()">
</body>
</html>
其实就这很简单,多谢楼上的哥哥费心了,不过还是要给你分,楼上哥哥看上去是个好人