| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 383 人关注过本帖
标题:求解,为什么这个函数的参数要这样写?
只看楼主 加入收藏
sd309515
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-7-17
结帖率:0
收藏
已结贴  问题点数:0 回复次数:3 
求解,为什么这个函数的参数要这样写?
这是个图片自动播放程序

<html>
<head>
<title>A Timed Slide Show</title>
<script type = "text/javascript">
<!-- hide me from older browsers
var the_images = new Array();
the_images[0] = new Image();
the_images[0].src = "one.jpg";
the_images[1] = new Image();
the_images[1].src = "two.jpg";
the_images[2] = new Image();
the_images[2].src = "three.jpg";
var the_timeout;
function rotateImage(index)
{
    window.document.my_image.src = the_images[index].src;
    index++;
    if (index >= the_images.length)
    {
        index = 0;
    }
    the_timeout = setTimeout("rotateImage("+index+");", 1000);
}
// show me -->
</script>
</head>
<body>
<img name = "my_image" src="one.jpg">
<form>
<input type = "button" value = "Start the Show" onClick = "rotateImage(0);">
<input type = "button" value = "Stop the Show" onClick = "clearTimeout(the_timeout);">
</form>
</body>
</html>

在下新手,可能在描述问题的时候有些细节无法讲清,请各位见谅。不明白的地方我用红色标出来了。谁能讲讲为什么要这样写,以及为什么将其替换成index程序会出错呢?
搜索更多相关主题的帖子: javascript head function title 自动播放 
2011-07-24 00:29
sd309515
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-7-17
收藏
得分:0 
顶一顶,让更多的人看到。
2011-07-24 16:29
小鸡啄米
Rank: 2
等 级:论坛游民
帖 子:2
专家分:10
注 册:2011-7-26
收藏
得分:10 
是不是问index 啊 ,index 是个变量,如果直接放在引号中的话,就变成了字符串,函数执行的时候直接是index 字符串  而不是数字 ,如果直接替换成index,语法就会出错,因为这是字符串拼接,setTimeout 第一个参数是可执行的代码串  到BAIDU 上找找吧
2011-07-26 10:24
sd309515
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-7-17
收藏
得分:0 
回复 3楼 小鸡啄米
setTimeout("rotateImage(index);", 1000); 这个写法不也是把变量放在括号内了吗?为什么还要多此一举给index加上双引号呢?setTimeout("rotateImage("+index+");", 1000);
我还有个疑问向您请教,为什么index的两边要加两个加号?目的是什么?
2011-07-27 16:20
快速回复:求解,为什么这个函数的参数要这样写?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033352 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved