如果再次单击相同按钮或单击其他按钮,如何隐藏Iframe?

时间:2014-02-15 07:11:07

标签: javascript html css

我可以通过iframe显示我的其他网页,但是当再次点击同一个按钮时,如何让它不可见或终止网页

<html>
<script type="text/javascript">  
function showIFrame() {  
  var iframe = document.getElementById("myiframe");  
 iframe.style.display="block";  
}  
</script>
<style>
#myiframe {
display:none; }
</style>
<body>
<iframe id="myframe" name="carsearch" width="535" height="625" scrolling="no"   frameborder="0"></iframe>
<form name="search" id="search" method="get" action="../crime_map/map_crime_pending.php" target="carsearch">

<button type="submit" id="SearchCarButton" class="submitBtn" onclick="showIFrame()"/>  <span>Search</span></button></form>
<button>Catcher</button>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试检查显示的代码,并根据当前状态进行更改;

   function showIFrame() {  
      var iframe = document.getElementById("myiframe");  
      var d = iframe.style.display;
      if(d=="block"){
         iframe.style.display = "none"  
      }else{
        iframe.style.display = "block";
      }
}