display显示隐藏
display
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style>#div1{ width:100px; height:200px; background:#ccc; display:none;} </style> <script> function showHide() { var oDiv=document.getElementById('div1'); //div是显示的 if(oDiv.style.display=='block'){ oDiv.style.display='none'; } else{ oDiv.style.display='block'; } } </script> </head> <body> <input type="button" value="显示隐藏" onclick="showHide()"> <div id="div1"></div> </body> </html>
点击按钮之后