代码之家  ›  专栏  ›  技术社区  ›  Alexan

脚本只在ie中有效

  •  0
  • Alexan  · 技术社区  · 15 年前

    我有以下用于显示运行行的javascript:

    <script type="text/javascript" language="javascript">
    
    
    //Change script's width (in pixels)
    var marqueewidth=800
    //Change script's height (in pixels, pertains only to NS)
    var marqueeheight=20
    //Change script's scroll speed (larger is faster)
    var speed=3
    //Change script's contents
    var marqueecontents='You text here'
    
    if (document.all)
    document.write('<marquee scrollAmount='+speed+' style="width:'+marqueewidth+'">'+marqueecontents+'</marquee>')
    
    function regenerate(){
    window.location.reload()
    }
    function regenerate2(){
    if (document.layers){
    setTimeout("window.onresize=regenerate",450)
    intializemarquee()
    }
    }
    
    function intializemarquee(){
    document.cmarquee01.document.cmarquee02.document.write('<nobr>'+marqueecontents+'</nobr>')
    document.cmarquee01.document.cmarquee02.document.close()
    thelength=document.cmarquee01.document.cmarquee02.document.width
    scrollit()
    }
    
    function scrollit(){
    if (document.cmarquee01.document.cmarquee02.left>=thelength*(-1)){
    document.cmarquee01.document.cmarquee02.left-=speed
    setTimeout("scrollit()",100)
    }
    else{
    document.cmarquee01.document.cmarquee02.left=marqueewidth
    scrollit()
    }
    }
    
    window.onload=regenerate2
    </script>
    

    我应该在脚本中做些什么来让它在ff和chrome中工作? 谢谢

    2 回复  |  直到 15 年前
        1
  •  2
  •   Martin Smith    15 年前

    您的代码包含 if (document.all) 所以字幕只能在ie中写入文档。

    我已经删除了这一行,它似乎在firefox中工作。我在这台机器上没有铬来测试。

        2
  •  2
  •   Delan Azabani    15 年前
    1. 缺少分号
    2. document.write()
    3. document.all
    4. <marquee>
    5. 全局变量
    6. 字符串为 setTimeout 功能
    7. 无缩进

    怀旧…好像是1998年。