| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7369 人关注过本帖
标题:参考网上做的轮播图片javascript,为何不起作用?
只看楼主 加入收藏
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
结帖率:100%
收藏
已结贴  问题点数:50 回复次数:16 
参考网上做的轮播图片javascript,为何不起作用?
程序代码:
<!DOCTYPE html>
<html>
<head><title>Javascript Window</title></head>
<body onload="init()">
<img id="pic" src="2.jpg" width="500" height="300" /><br />
<input type="button" value="1" onmouseover="onMouseHover(this)" />
<input type="button" value="2" onmouseover="onMouseHover(this)" />
<input type="button" value="3" onmouseover="onMouseHover(this)" />

<script type="text/javascript">
var arrImage=new array("1.jpg","2.jpg","3.jpg");
var Timer=self.setInterval("play()",1000);
var count=0;
function play()
{
  if(arrImage.length==count)  count=0;
  document.getElementById("pic").src=arrImage[count];
  count++;
}
function clearTimer()
{
  window.clearInterval(Timer);
}
function onMouseHover(obj)
{
  clearTimer();
  var index=parseInt(obj.value);
  document.getElementById("pic").src=arrImage[index-1];
  count=index;
}
function onMouseLeave()
{
  Timer=self.setInterval("play()",1000);
}
function init()
{
  var btns=document.getElementByTagName("input");
  for(var i=0;i<btns.length;i++)
  {
     btns[i].onmouseout=onMouseLeave;
  }
}
</script>
</body>
</html>


[此贴子已经被作者于2016-1-29 23:22编辑过]

搜索更多相关主题的帖子: javascript button title 图片 网上 
2016-01-29 10:20
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
路径指向问题吧

剑栈风樯各苦辛,别时冰雪到时春
2016-01-29 20:51
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:50 
程序代码:
<!DOCTYPE html>
<html>
<head><title>Javascript Window</title>
<script type="text/javascript">
var Timer=self.setInterval("play()",1000);
var count=1;
function play()
{
    document.getElementById("pic").src="images/"+count+".jpg";
    count++;
    if(count>3)
        count=1;
}
function clearTimer()
{
      window.clearInterval(Timer);
}
function onMouseHover(obj)
{
    clearTimer();
      var index=parseInt(obj.value);
      document.getElementById("pic").src="images/"+index+".jpg";
      count=index;
}
function onMouseLeave()
{
      Timer=self.setInterval("play()",1000);
}
function init()
{
      var btns=document.getElementsByTagName("input");
      for(var i=0;i<btns.length;i++)
      {   
         btns[i].onmouseout=onMouseLeave;
      }
}
</script>
</head>
<body onload="init()">
<img id="pic" src="images/1.jpg" width="500" height="300" /><br />
<input type="button" value="1" onmouseover="onMouseHover(this)" />
<input type="button" value="2" onmouseover="onMouseHover(this)" />
<input type="button" value="3" onmouseover="onMouseHover(this)" />

</body>
</html>


剑栈风樯各苦辛,别时冰雪到时春
2016-01-29 21:26
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
回复 2楼 林月儿
大神,你的代码可以运行,请明示路径指向问题是什么?是因为路径放在数组里面有问题?
程序代码:
<!DOCTYPE html>
<html>
<head>
<title>Image</title>
<meta charset="utf-8">
</head>
<body>
<img id="pic" src="images/1.jpg" width="500" height="300" /><br />
<input type="button" value="1" onmouseover="onMouseHover(this)" onmouseout="onMouseLeave()" />
<input type="button" value="2" onmouseover="onMouseHover(this)" onmouseout="onMouseLeave()" />
<input type="button" value="3" onmouseover="onMouseHover(this)" onmouseout="onMouseLeave()" />

<script type="text/javascript">
//var arrImage=new array("images/1.jpg","images/2.jpg","images/3.jpg");
var Timer=self.setInterval("play()",1000);
var count=1;
function play()
{
  if(count>3)  count=1;
  document.getElementById("pic").src="images/"+count+".jpg";
  count++;
}
function clearTimer()
{
  window.clearInterval(Timer);
}
function onMouseHover(obj)
{
  clearTimer();
  var index=parseInt(obj.value);
  document.getElementById("pic").src="images/"+index+".jpg";
  count=index;
}
function onMouseLeave()
{
  Timer=self.setInterval("play()",1000);
}
</script>
</body>
</html>


[此贴子已经被作者于2016-1-29 23:57编辑过]


   唯实惟新 至诚致志
2016-01-29 23:09
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
恩,路径是小问题,访问权限才是大问题啦

剑栈风樯各苦辛,别时冰雪到时春
2016-01-31 19:20
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
数组是可以放的,你写的相对路径应该也没问题,是我一开始说错了吧,,,,能跑就好

剑栈风樯各苦辛,别时冰雪到时春
2016-01-31 19:21
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
回复 6楼 林月儿
论坛里好冷清,纵然你没有说清楚root case,但还是非常感谢你。

   唯实惟新 至诚致志
2016-01-31 23:33
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
我是菜鸟啦,大虾那是你的qq吗

剑栈风樯各苦辛,别时冰雪到时春
2016-02-01 10:51
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
回复 8楼 林月儿
是啊,注册的时候没注意,这ID不好。

   唯实惟新 至诚致志
2016-02-01 11:37
keith123456
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-11-28
收藏
得分:0 
回复 6楼 林月儿
function onMouseLeave()
{
      Timer=self.setInterval("play()",1000);
}

如果这里使用局部变量var Timer =  ...
当鼠标在buttom移动的时候,图片轮播的速度会变快?
2016-03-02 16:53
快速回复:参考网上做的轮播图片javascript,为何不起作用?
数据加载中...
 
   



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

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