求JS高手解答 图片切换问题
js文件:varnum=0;vartimeID;functionchangeImg(){varpic=document.getElementById("pic");var...
js文件:
var num=0;
var timeID;
function changeImg(){
var pic = document.getElementById("pic");
var img = document.getElementsByName("img");
num++;
if(num>3){
num=1;
}
//alert(num);
for(var i=0;i<img.length;i++){
if(img[i].innerHTML==num){
img[i].style.background="#28344D";
}else{
img[i].style.background="";
}
}
pic.src="images/pic/" + num+".jpg";
timeID = setTimeout("changeImg()",2000);
}
function mouseover(o){
var pic = document.getElementById("pic");
var img = document.getElementsByName("img");
pic.src = "images/pic/" + o.innerHTML + ".jpg";
for(var i=0;i<img.length;i++){
alert(o.innerHTML);
if(img[i].innerHTML==o.innerHTML){
img[i].style.background="#28344D";
}else{
img[i].style.background="";
}
}
clearTimeout(timeID);
}
function mouseout(){
changeImg();
}
html:
<div class=signing-img style="background:#FF6699">
<a href="#"><img id="pic" src="images/pic/1.jpg" class=img-size></a>
<div class="bottom-text">
<a class="text-a" href="" id="img" onMouseOver="mouseover(this)" onMouseOut="mouseout()">1</a>
<a class="text-a" href="" id="img" onMouseOver="mouseover(this)" onMouseOut="mouseout()">2</a>
<a class="text-a" href="" id="img" onMouseOver="mouseover(this)" onMouseOut="mouseout()">3</a>
</div>
</div>
为什么mouseover()函数在加了alert那句后就能修改背景颜色成功,注释掉就不行啊?还有前面改变图片,图片是改了 但是下面那个改颜色没有改成功又是怎么个回事?改颜色哪里,修改是成功了的,但是显示上没有效果不知道为什么?昨天都一切正常,今天就不行了,坑爹啊。。。。 展开
var num=0;
var timeID;
function changeImg(){
var pic = document.getElementById("pic");
var img = document.getElementsByName("img");
num++;
if(num>3){
num=1;
}
//alert(num);
for(var i=0;i<img.length;i++){
if(img[i].innerHTML==num){
img[i].style.background="#28344D";
}else{
img[i].style.background="";
}
}
pic.src="images/pic/" + num+".jpg";
timeID = setTimeout("changeImg()",2000);
}
function mouseover(o){
var pic = document.getElementById("pic");
var img = document.getElementsByName("img");
pic.src = "images/pic/" + o.innerHTML + ".jpg";
for(var i=0;i<img.length;i++){
alert(o.innerHTML);
if(img[i].innerHTML==o.innerHTML){
img[i].style.background="#28344D";
}else{
img[i].style.background="";
}
}
clearTimeout(timeID);
}
function mouseout(){
changeImg();
}
html:
<div class=signing-img style="background:#FF6699">
<a href="#"><img id="pic" src="images/pic/1.jpg" class=img-size></a>
<div class="bottom-text">
<a class="text-a" href="" id="img" onMouseOver="mouseover(this)" onMouseOut="mouseout()">1</a>
<a class="text-a" href="" id="img" onMouseOver="mouseover(this)" onMouseOut="mouseout()">2</a>
<a class="text-a" href="" id="img" onMouseOver="mouseover(this)" onMouseOut="mouseout()">3</a>
</div>
</div>
为什么mouseover()函数在加了alert那句后就能修改背景颜色成功,注释掉就不行啊?还有前面改变图片,图片是改了 但是下面那个改颜色没有改成功又是怎么个回事?改颜色哪里,修改是成功了的,但是显示上没有效果不知道为什么?昨天都一切正常,今天就不行了,坑爹啊。。。。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询