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函数中代码没有完全执行,功能不正常的现象,我该怎么解决,谢谢指点

解决方案 »

  1.   

    在ScrollButton最后加return true;
      

  2.   

    像凡可 京东学习。  不管IE几, 都默认为IE6 或者IE7 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />  我这个是 不管IE几 都按IE7处理. 但是我觉得得高于IE7的才会转回IE7  IE6就不行了,  你可以把  7改成6
      

  3.   

    不管是ie几,写的js代码如果出现错误都看不到真难过!
      

  4.   

    这个我试过了,没有效果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";
    }
    }
    return true;
    }
      

  5.   

    试试这样
    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
      

  6.   

    本帖最后由 net_lover 于 2010-12-08 16:46:11 编辑
      

  7.   

    我添加alert进去,看到在if(i == index)
            {
                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"),也没有提示
      

  8.   

    这是HTML中相关的一部分,点击时调用PauseScroll,在PauseScroll中调用ScrollPicShow是可以正常显示图片的,上面说的问题,是首次加载的时候的问题<table width="254" border="0" align="left" cellpadding="0" cellspacing="2">
    <tr>
     <td width="80" bgcolor="#ececec">&nbsp;</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);
    }
      

  9.   

    这个是之前做的一个网站中的一段代码我抠出来的,现在环境变成了win2003+IIS6.0+SQL2005,就出现了这种情况,我搜过,给出的解释中有提到<img id="ScrollImg" src="javascript:ScrollPicShow(0,false);" width="251" height="137" border=0 style="FILTER: revealTrans(duration=1,transition=5);" />src="javascript:ScrollPicShow(0,false);" 是ie6内核支持的,到ie8貌似就不再支持了
      

  10.   

    对,ie7之后是不执行的
    你需要window.onload=function(){
    ScrollPicShow(0,false);
    }
      

  11.   

    ScrollPicShow(0,false)给index赋值是0,那么在ScrollPicShow函数体中,index的值应该是0吧?
      

  12.   

    ie7之后是不执行的src="javascript代码的"
      

  13.   


    <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";
            }
        }
    }
    实现的是一个图片交替显示的功能,点击按钮浏览图片的时候是正常的
    这个问题主要出现在页面首次加载的过程中
      

  14.   

    我将相关的代码完整的帖出来<script>
    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">&nbsp;</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>
      

  15.   

    你的ScrollPicShow(0,false);
    要放在页面的最后执行,或者window.onload里面。,
    <td width="26" class="ScrollButton1" id="ScrollDiv0" onClick="PauseScroll(0)">1</td>这些对象还没加载你就使用,能不报错吗》?》》
      

  16.   

    呵呵,看
    现在问题解决了,是在下面代码中添加一行<script>ScrollPicShow(0,true);</script>就可以了<table id="mytable" width="254" border="0" align="left" cellpadding="0" cellspacing="2">
    <tr>
    <td width="80" bgcolor="#ececec">&nbsp;</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>