function ScrollPicShow(index,isContinue)
{
...
ScrollButton(index);//调用函数ScrollButton
...
}
function ScrollButton(index)
{
var buttonName = "ScrollDiv";
for(var i=0;i<5;i++)
{
var sbut = document.getElementById(buttonName+i);
if(i == index)
{
sbut.className = "ScrollButton1";
}
else
{
sbut.className = "ScrollButton0";
}
}
}在上面的javascript中ScrollPicShow调用了ScrollButton,正常的我们希望ScrollButton返回到ScrollPicShow并执行下面的代码,而在ie8以上的浏览器版本中ScrollButton执行后却没有返回到ScrollPicShow,直接跳出ScrollButton,造成ScrollPicShow函数中代码没有完全执行,功能不正常的现象,我该怎么解决,谢谢指点
{
alert("enter ScrollButton");
var buttonName = "ScrollDiv";
for(var i=0;i<5;i++)
{
var sbut = document.getElementById(buttonName+i);
if(i == index)
{
sbut.className = "ScrollButton1";
}
else
{
sbut.className = "ScrollButton0";
}
}
return true;
}
var buttonName = "ScrollDiv";
for(var i=0;i<5;i++)
{
var sbut = document.getElementById(buttonName+i);
sbut.className = "ScrollButton0";
}
document.getElementById(buttonName+ index).className="ScrollButton1"另外,你的ScrollDiv的 id正确吗
ScrollDiv0 ..... ScrollDiv4
{
alert("set sbut className");
sbut.className = "ScrollButton1";
}这种情况下可以提示set sbut className
而if(i == index)
{
sbut.className = "ScrollButton1";
alert("set sbut className");
}就无效,根本不会提示set sbut className
并且在调用ScrollButton函数的下一句我添加了alert("return"),也没有提示
<tr>
<td width="80" bgcolor="#ececec"> </td>
<td width="26" class="ScrollButton1" id="ScrollDiv0" onClick="PauseScroll(0)">1</td>
<td width="26" class="ScrollButton0" id="ScrollDiv1" onClick="PauseScroll(1)">2</td>
<td width="26" class="ScrollButton0" id="ScrollDiv2" onClick="PauseScroll(2)">3</td>
<td width="26" class="ScrollButton0" id="ScrollDiv3" onClick="PauseScroll(3)">4</td>
<td width="26" class="ScrollButton0" id="ScrollDiv4" onClick="PauseScroll(4)">5</td>
</tr>
</table>
function PauseScroll(index)
{
isPause = true;
ScrollPicShow(index,false);
window.setTimeout("isPause = false",5000);
}
你需要window.onload=function(){
ScrollPicShow(0,false);
}
<script language="javascript" type="text/javascript">
alert("begin");
ScrollPicShow(0,false);
alert("end");
</script><img id="ScrollImg" width="251" height="137" border=0
style="FILTER: revealTrans(duration=1,transition=5);" />我把代码改成了这样,代码可以执行了,但是当执行到下面的函数中后就跳出了,不在执行调用ScrollButton的函数ScrollPicShow中其他的代码function ScrollButton(index)
{
var buttonName = "ScrollDiv";
for(var i=0;i<5;i++)
{
var sbut = document.getElementById(buttonName+i);
if(i == index)
{
sbut.className = "ScrollButton1";
}
else
{
sbut.className = "ScrollButton0";
}
}
}
实现的是一个图片交替显示的功能,点击按钮浏览图片的时候是正常的
这个问题主要出现在页面首次加载的过程中
function PlayTran()
{
if(document.all)
{
document.getElementById('ScrollImg').filters.revealTrans.Transition=10;
document.getElementById('ScrollImg').filters.revealTrans.apply();
document.getElementById('ScrollImg').filters.revealTrans.play();
}
}
function ScrollPicShow(index,isContinue)
{
alert("enter ScrollPicShow");
if(isPause && isContinue)
{
window.setTimeout("ScrollPicShow("+index+",true)",5000);
return;
}
ScrollButton(index);
alert("I am here");
var simg = document.getElementById("ScrollImg");
var stxt = document.getElementById("ScrollTxt");
var surl = document.getElementById("ScrollUrl");
var stxturl = document.getElementById("ScrollTxtUrl");
PlayTran();
simg.src = scrollImg[index][2];
stxturl.title = simg.title = surl.title = stxt.innerText = scrollImg[index][1];
stxturl.href = surl.href = scrollImg[index][0];
//按钮显示
//定时滚动下一张
if(index >= scrollImg.length-1 || index>=5)
{
index = 0;
}
else
{
index++;
}
if(isContinue)
{
window.setTimeout("ScrollPicShow("+index+",true)",5000);
}
}
function ScrollButton(index)
{
alert("enter ScrollButton");
var buttonName = "ScrollDiv";
for(var i=0;i<5;i++)
{
var sbut = document.getElementById(buttonName+i);
if(i == index)
{
sbut.className = "ScrollButton1";
}
else
{
sbut.className = "ScrollButton0";
}
}
}
function PauseScroll(index)
{
isPause = true;
ScrollPicShow(index,false);
window.setTimeout("isPause = false",5000);
}
</script>
<table width="490" height="167" align="center" cellpadding="0" cellspacing="6">
<tr>
<td width="476" height="153">
<table height="126">
<tr><td height="137">
<script language="javascript" type="text/javascript">
alert("begin");
ScrollPicShow(0,false);
alert("end");
</script>
<div align="center" style="height:137px">
<a id="ScrollUrl" href="#" target="_blank">
<img id="ScrollImg" width="251" height="137" border=0
style="FILTER: revealTrans(duration=1,transition=5);" />
</a></div>
</td>
<td width="200" target="_blank" valign="top">
<table style="table-layout:fixed; word-break:break-all; width:200px">
<br>
<tr><td width="199px" valign="top" height="100">
<a href="#" id="ScrollTxtUrl" style="overflow:hidden; text-overflow:ellipsis;" class="red12" target="_blank"><span id="ScrollTxt"></a>
</td>
</tr></table></td></tr>
</table>
<table width="254" border="0" align="left" cellpadding="0" cellspacing="2">
<tr>
<td width="80" bgcolor="#ececec"> </td>
<td width="26" class="ScrollButton1" id="ScrollDiv0" onClick="PauseScroll(0)">1</td>
<td width="26" class="ScrollButton0" id="ScrollDiv1" onClick="PauseScroll(1)">2</td>
<td width="26" class="ScrollButton0" id="ScrollDiv2" onClick="PauseScroll(2)">3</td>
<td width="26" class="ScrollButton0" id="ScrollDiv3" onClick="PauseScroll(3)">4</td>
<td width="26" class="ScrollButton0" id="ScrollDiv4" onClick="PauseScroll(4)">5</td>
</tr>
</table>
</td>
</tr>
</table>
要放在页面的最后执行,或者window.onload里面。,
<td width="26" class="ScrollButton1" id="ScrollDiv0" onClick="PauseScroll(0)">1</td>这些对象还没加载你就使用,能不报错吗》?》》
现在问题解决了,是在下面代码中添加一行<script>ScrollPicShow(0,true);</script>就可以了<table id="mytable" width="254" border="0" align="left" cellpadding="0" cellspacing="2">
<tr>
<td width="80" bgcolor="#ececec"> </td>
<td width="26" class="ScrollButton1" id="ScrollDiv0" onClick="PauseScroll(0)">1</td>
<td width="26" class="ScrollButton0" id="ScrollDiv1" onClick="PauseScroll(1)">2</td>
<td width="26" class="ScrollButton0" id="ScrollDiv2" onClick="PauseScroll(2)">3</td>
<td width="26" class="ScrollButton0" id="ScrollDiv3" onClick="PauseScroll(3)">4</td>
<td width="26" class="ScrollButton0" id="ScrollDiv4" onClick="PauseScroll(4)">5</td>
</tr>
</table>
<script>ScrollPicShow(0,true);</script>