2010-08-07 92 views
0

問題在於:圖層被成功隱藏,但是當我再次單擊按鈕時,它不會重新出現。有任何想法嗎?.show()沒有顯示HTML元素

<head> 
    ... 
    <script type="text/javascript" 
     src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> 
    </script> 

    <script type="text/javascript"> 
    function action() { 
     var status; 
     status = 1; 

     if(status == 1) { 
      $("#Layer1").hide("slow"); 
      $("#close").attr("src", "open.jpg"); 
      status = 0; 
     } else if(status == 0) { 
      status = 1; 
      $("#Layer1").show("slow"); 
      $("#close").attr("src", "close.jpg"); 
     } 
    } 
    </script> 
    <style type="text/css"> 
    body { 
     background-color: #000000; 
    } 
    #Layer1 { 
     position: absolute; 
     width: 200px; 
     height: 115px; 
     z-index: 1; 
     left: 179px; 
     top: 3px; 
    } 
    #Layer2 { 
     position: absolute; 
     width: 101px; 
     height: 80px; 
     z-index: 2; 
     left: 570px; 
     top: 473px; 
    } 
    </style> 

</head> 

<body> 
    <div id="Layer1"><img src="body.jpg" width="842" height="554" /></div> 
    <div id="Layer2"><img src="close.jpg" id="close" width="63" height="64"  
     OnClick="action()"/></div> 
</body> 

回答

3

定義statusaction功能外,否則它開始了與每次1

var status = 1; function action(){} 

如果你的邏輯是正確的,這應該工作。