<script> 
function hideorshow(id) 

var table=document.getElementById(id); 
if(table==null)alert(111); 
if(table.style.display=='block') 
table.style.display='none'; 
else 
table.style.display='block'; 

</script>  
  <body> <table border=1> 
<tr>
    <td onclick="hideorshow('t1')" onmouseover="this.style.cursor='hand'">navigation1 </td>
</tr> 
  </table> 
<table border=1 id="t1" style="display:block"> <tr> <td>menu1 </td> </tr> 
<tr> <td>menu2 </td> </tr> 
<tr> <td>menu3 </td> </tr> 
<tr> <td>menu4 </td> </tr>
  </table>   </body>
</html>

解决方案 »

  1.   


    <script>
    functionhideorshow(id) 
    {
         vartable=document.getElementById(id);  //根据id获取对象
         if(table==null) alert(111);  //如果对象为空,打印111
         if(table.style.display=='block') //如果对象不可见
         table.style.display='none';   //那么将对象隐藏
         else 
         table.style.display='block';  //否则显示
    }
    </script>
    <body>
    <tableborder=1>
    <tr>
    <td onclick="hideorshow('t1')"onmouseover="this.style.cursor='hand'">navigation1
    </td>
    </tr>
    </table>
    <tableborder=1id="t1"style="display:block"><tr><td>menu1</…
      

  2.   


     <script> 
    //对应单击单元格的函数
    function hideorshow(id) 

        //var table=document.getElementById(id); //此时只有一个id
        var table=document.getElementById("t1");//如果有多个id,根据id获取对象 
        if(table==null)alert(111); //如果无此对象,就弹出111的信息
        //判断此对象现在是否是显示
        if(table.style.display=='block') 
            //如果当前是显示,就隐藏起来
            table.style.display='none'; 
        else 
            //如果当前是隐藏,就显示出来
            table.style.display='block'; 

    </script>  
      <body>    <table border=1> 
            <tr>
               <!--onclick:点击此单元格调用此函数,鼠标移到此单元格上鼠标显示为手型-->
               <td onclick="hideorshow('t1')" onmouseover="this.style.cursor='hand'">navigation1 </td>
            </tr> 
         </table> 
        <!--style="display:block"让这个表格充满所在区域(也就是显示)--->
        <table border=1 id="t1" style="display:block"> <tr> <td>menu1 </td> </tr> 
            <tr> <td>menu2 </td> </tr> 
            <tr> <td>menu3 </td> </tr> 
            <tr> <td>menu4 </td> </tr>
         </table>   </body>
    </html>