一个简单的问题,求指教~~· 本帖最后由 manman300 于 2010-04-15 21:14:52 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 document.getElementById("apDiv"+i).style.display="block";代码缺少对象 楼主,我这有个思想,你是想实现图片的轮流播放,间隔几秒就换个img 的URL 把 你要的url 存入到数组中! 不知道怎么做 的 我这里有代码 ! setTimeout(imgChange(),1000); 这句改成setTimeout(imgChange, 1000); setTimeout(imgChange(),1000); 这只执行一次呀。setInterval(imgChange(),1000); 这是每隔一秒执行一下次吧。 <!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=utf-8" /><title>无标题文档</title><script language="javascript"> var nowShow=1; var maxShow=3; function imgChange(){ for(var i=1;i<maxShow+1;i++){ if(nowShow==i) document.getElementById("apDiv"+i).style.display="block"; else document.getElementById("apDiv"+i).style.display="none"; } if(nowShow!=maxShow) nowShow++; else nowShow=1; } setInterval(imgChange,1000); </script><style type="text/css"> <!-- #apDiv1 { position:absolute; left:231px; top:13px; width:600; height:450; z-index:1; } #apDiv2 { position:absolute; left:231px; top:13px; width:600; height:450; z-index:2; } #apDiv3 { position:absolute; left:231px; top:13; width:600; height:450; z-index:3; } --></style></head><body > <div id="apDiv1"><img src="image/照片 098.jpg" width="600" alt="1" height="450" /></div> <div id="apDiv2"><img src="image/照片 103.jpg" width="600" alt="2" height="450" /></div> <div id="apDiv3"><img src="image/照片 128.jpg" width="600" alt="3" height="450" /></div></body></html> setInterval("imgChange()",1000); 这样才对。 这位兄弟, setInterval(imgChange,1000); 这个我用了个alert的语句获取是能起作用了,但是实现不断的弹出对话框了,但是返回的值都是object类型,没有获取得到ID,图片也没变化,难道是我别的语句有问题?希指教,还有我在网上查了setTimeout(code,delay)不是每隔delay的值就会运行一次code吗?只是他会先运行setTimeout程序,然后再执行code,相比setInterval只是时间延长了而已,不知道这种说法对不对?再说setTimeout也能实现时间自动刷新的功能啊,那这个又怎么解析他只执行一次呢? setTimeout("imgChange()",1000); 才可以 语法问题 楼上的,我知道语法是可以写成setTimeout("imgChange()",1000); 或者是setTimeout(imgChange,1000);但是关键现在是不能实现我要的效果。望知道的朋友指教,或许是我别的语句有问题。 setTimeout应该写在imgChange方法的最后一行,外部再写一个调用imgChange。getElementById获取的对象就是[Object] [Quote=引用 8 楼 free_wind22 的回复:]HTML code<!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"> 已经解决,谢谢各位,是不小心把var nowShow=1;放到imgChange()函数里了,导致每次都是显示第一张,低级错误啊~~不好意思,各位,谢谢了! 关于JQ,很有意思的一个东西,高手们,小弟不才,又来...向大神们请教了。 求助:页面数据定时刷新 求分页js代码 关于获取窗口高度和宽度的问题 jquery ui dialog的内容显示 想深入系统的学习一下javascript,哪位朋友帮忙介绍基本这方面的电子图书的下载,谢谢~ 求救,正则表达式的写法 大家是怎样得到这个子窗口中的值呀? 上了一个网站后,IE的默认主页就不能修改了,每次一上网就进入这个网站,烦! VUE和Bootstrap使用Table的一个问题 关于JS意外的调用了方法或属性访问 一张大图上任意贴几张小图
代码缺少对象
这只执行一次呀。
setInterval(imgChange(),1000);
这是每隔一秒执行一下次吧。
<!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=utf-8" />
<title>无标题文档</title>
<script language="javascript">
var nowShow=1;
var maxShow=3;
function imgChange(){
for(var i=1;i<maxShow+1;i++){
if(nowShow==i)
document.getElementById("apDiv"+i).style.display="block";
else
document.getElementById("apDiv"+i).style.display="none";
}
if(nowShow!=maxShow)
nowShow++;
else
nowShow=1;
}
setInterval(imgChange,1000);
</script>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:231px;
top:13px;
width:600;
height:450;
z-index:1;
}
#apDiv2 {
position:absolute;
left:231px;
top:13px;
width:600;
height:450;
z-index:2;
}
#apDiv3 {
position:absolute;
left:231px;
top:13;
width:600;
height:450;
z-index:3;
}
-->
</style>
</head><body >
<div id="apDiv1"><img src="image/照片 098.jpg" width="600" alt="1" height="450" /></div>
<div id="apDiv2"><img src="image/照片 103.jpg" width="600" alt="2" height="450" /></div>
<div id="apDiv3"><img src="image/照片 128.jpg" width="600" alt="3" height="450" /></div>
</body>
</html>
这位兄弟, setInterval(imgChange,1000); 这个我用了个alert的语句获取是能起作用了,但是实现不断的弹出对话框了,但是返回的值都是object类型,没有获取得到ID,图片也没变化,难道是我别的语句有问题?希指教,还有我在网上查了setTimeout(code,delay)不是每隔delay的值就会运行一次code吗?只是他会先运行setTimeout程序,然后再执行code,相比setInterval只是时间延长了而已,不知道这种说法对不对?再说setTimeout也能实现时间自动刷新的功能啊,那这个又怎么解析他只执行一次呢?
getElementById获取的对象就是[Object]
HTML code<!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">