怎样通过javascript显示和隐藏控件

 

<html>
  
<head>
   
<body>
    
<script language="javascript">
        
       
function show(){
          document.form1.b3.style.display
=""   设置""时为显示
          document.form1.b4.style.display
=""  
          document.form1.txt.style.display
="" 
       }

       
       
function hid(){
          document.form1.b3.style.display
="none"  设置"none"时为隐藏
          document.form1.b4.style.display
="none"
          document.form1.txt.style.display
="none"
       }

       
    
</script>
     <form id="form1" name="form1">
        
<input type="button" name="but1" value="显示" onclick="show()"/>
        <input type="button" name="but2" value="隐藏" onclick="hid()"/>
        <input type="button" name="b3" id="but3" value="Hello"/>
        <input type="button" name="b4" id="but3" value="World"/>
        <input type="text" name="txt" id="txt"/>
     </form>
   </body>
  </head>
</html>


主要通过设置表单元素的style.display来实现隐藏和显示.

posted @ 2008-06-19 20:00  Shinepolo  阅读(3905)  评论(0)    收藏  举报