<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml">   
    <head>   
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"/>   
        <title>Untitled Document</title>   
        <style type="text/css">   
            #logo1 {
  left:100px;
top:200px;   
                width: 52px;   
                height: 37px;     
                background: url(http://www.zzsky.cn/effect/images/2008901080950.gif) 0px 0px;   
            } 
            #logo2{   
left:100px;
top:300px;
                width: 52px;   
                height: 37px;     
                background: url(http://www.zzsky.cn/effect/images/2008901080950.gif) 0px 37px;   
            }   
        </style>   
        <script type="text/javascript">  
            function dsp(o,n, playing){
     if (n <= 6 && n >= 0) {   
                    var button = document.getElementById("o");   
                    var width = 52;   
                    var offsetWidth = -width * n;   
                    button.style.backgroundPosition = offsetWidth + "px 37px";   
                    n = playing ? n + 1 : n - 1;   
                    setTimeout("dsp("+ o +"" + n + "," + playing + ")", 45);   
                }                 
            }  
        </script>   
    </head>   
  
    <body>   
        <div id="logo1" onmouseover="dsp("logo1",1, true);" onmouseout="dsp("logo1",6);">&nbsp;</div>
<div id="logo2" onmouseover="dsp("logo2",1, true);" onmouseout="dsp("logo2",6);">&nbsp;</div>   
    </body>   
</html>  
高手帮忙下,总报LOGO1,LOGO2没定义

解决方案 »

  1.   

    指出两点:1.onmouseover="dsp('logo1',1, true);"  双引号里的变量用单引号2.var button = document.getElementById(o);  o本来就是个字符串,就不需要引号了3.逻辑还有问题 自己可以检查下.
      

  2.   

    1.改onmouseover="dsp('logo1',1, true);" onmouseout="dsp('logo1',6,false);" logo2类似
    2.改var button = document.getElementById(o); 
    3.改 setTimeout("dsp('"+ o +"'," + n + "," + playing + ")", 45); 
    以下代码运行通过<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">  
        <head>  
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"/>  
            <title>Untitled Document </title>  
            <style type="text/css">  
                #logo1 { 
      left:100px; 
    top:200px;  
                    width: 52px;  
                    height: 37px;    
                    background: url(http://www.zzsky.cn/effect/images/2008901080950.gif) 0px 0px;  
                } 
                #logo2{  
    left:100px; 
    top:300px; 
                    width: 52px;  
                    height: 37px;    
                    background: url(http://www.zzsky.cn/effect/images/2008901080950.gif) 0px 37px;  
                }  
            </style>  
            <script type="text/javascript">  
                function dsp(o,n, playing){ 
        if (n <= 6 && n >= 0) {  
                        var button = document.getElementById(o);  
                        var width = 52;  
                        var offsetWidth = -width * n;  
                        button.style.backgroundPosition = offsetWidth + "px 37px";  
                        n = playing ? n + 1 : n - 1;  
                        setTimeout("dsp('"+ o +"'," + n + "," + playing + ")", 45);  
                    }                
                }  
            </script>  
        </head>  
      
        <body>  
            <div id="logo1" onmouseover="dsp('logo1',1, true);" onmouseout="dsp('logo1',6,false);">&nbsp; </div> 
    <div id="logo2" onmouseover="dsp('logo2',1, true);" onmouseout="dsp('logo2',6,false);">&nbsp; </div>  
        </body>  
    </html>