for(t=0;t <11;t++) 

        z=a[t]; 
        document.getElementById(a[t].toString()).onmouseout=function(){menu1_change1(z);}; 这句调用不成功,如果把z换成常量,就能调用成功,不知问什么?请大家指教         } 

解决方案 »

  1.   

     document.getElementById(a[t]).onmouseout= function(){eval("menu1_change1('" + z +"')");};
      

  2.   

    问题出在这里:
    定义 var a=[];
      

  3.   

     <BODY onload="open_menu()">
    <div id="menu_1_a_1" style="width:200px;background-color:yellow;height:30px;">sssss</div>
    <div id="menu_2_a_1" style="width:200px;background-color:red;height:30px;">sssss</div>
    <div id="menu_2_a_2" style="width:200px;background-color:yellow;height:30px;">sssss</div>
    <div id="menu_2_a_3" style="width:200px;background-color:red;height:30px;">sssss</div>
    <div id="menu_2_a_4" style="width:200px;background-color:yellow;height:30px;">sssss</div>
    <div id="menu_2_a_5" style="width:200px;background-color:red;height:30px;">sssss</div>
    <div id="menu_2_a_6" style="width:200px;background-color:yellow;height:30px;">sssss</div>
    <div id="menu_2_a_7" style="width:200px;background-color:red;height:30px;">sssss</div>
    <div id="menu_2_a_8" style="width:200px;background-color:yellow;height:30px;">sssss</div>
    <div id="menu_2_a_9" style="width:200px;background-color:red;height:30px;">sssss</div>
    <div id="menu_2_a_10" style="width:200px;background-color:yellow;height:30px;">sssss</div>
     <script>
      function menu1_change1(menu) 

    alert(menu); 
    document.getElementById(menu).style.backgroundColor="#ffffff"; 
    document.getElementById(menu).style.borderTop="0px"; 
    document.getElementById(menu).style.borderBottom="0px"; 
    } function open_menu() 
    { //alert(document.getElementById("menu_1_a_1").outerHTML);
    var a=[];

    a[0]="menu_1_a_1"; 
    a[1]="menu_2_a_1"; 
    a[2]="menu_2_a_2"; 
    a[3]="menu_2_a_3"; 
    a[4]="menu_2_a_4"; 
    a[5]="menu_2_a_5"; 
    a[6]="menu_2_a_6"; 
    a[7]="menu_2_a_7"; 
    a[8]="menu_2_a_8"; 
    a[9]="menu_2_a_9"; 
    a[10]="menu_2_a_10"; 

    for(var t=0;t <11;t++) 

    z=a[t]; 

    document.getElementById(a[t]).onmouseout=function(){menu1_change1(z);}; //这句调用不成功,如果把z换成常量,就能调用成功,不知问什么?请大家指教  } 

    </script>
     </BODY>
      

  4.   

    同意楼上,你没定义数组a,加上var a=[];就可以吧
      

  5.   

    另外在循环里面加上这个估计能实现你的效果
       for(t=0;t <11;t++) 
        { 
           (function ()
           {
                var z=a[t]; 
                document.getElementById(z).onmouseout=function(){menu1_change1(z);}; 
            }
            )();
         }
      

  6.   

    不是不成功,是每次调用 t总等于 menu_2_a_10这样改下
    for(t=0;t <11;t++) 

    z=a[t]; 
    document.getElementById(a[t]).onmouseout=(function(z){ // 这句调用不成功,如果把z换成常量,就能调用成功,不知问什么?请大家指教 
    return function (){
    menu1_change1(z);
    }
    })(z); 
      

  7.   

    写错了,是 z总等于 menu_2_a_10 
      

  8.   

    写错了,是 z总等于 menu_2_a_10