<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title> </title> <style type="text/css"> #div1{ width: 200px; height: 200px; background: red; display: none; } </style> <script type="text/javascript"> window.onload=function(){ var obtn1=document.getElementById("btn"); obtn1.onclick=function(){ var oDiv=document.getElementById("div1"); if(oDiv.style.display=="none"){ oDiv.style.display="block"; } else{ oDiv.style.display="none"; } } } </script> </head> <body> <input type="button" name="" id="btn" value="顯示隱藏" /> <div id="div1"> </div> </body></html>
需要點擊兩下按鈕才顯示,之后就沒事,將if else的條件互換就一點問題沒有,有沒有人懂這是什么原因造成的
Youruncle
2016-08-18 16:57:16