onclick 显示 <p><h1><iframe> ,函数 showHide(shID)

onclick to show <p><h1><iframe> , function showHide(shID)

我做了一个 onclick showHide 功能,但在一个部分中只显示 1 个元素。当人们点击阅读更多按钮时,将显示段落以及视频或一些图像。 我怎样才能点击显示标题、段落和 iframe? 感谢帮助 !

<style type="text/css">
   /* This CSS is used for the Show/Hide functionality. */
   .more {
      display: none;
      border-top: 1px solid #666;
      border-bottom: 1px solid #666; }
   a.showLink, a.hideLink {
      text-decoration: none;
      color: #36f;
      padding-left: 8px;
      background: transparent url(down.gif) no-repeat left; }
   a.hideLink {
      background: transparent url(up.gif) no-repeat left; }
   a.showLink:hover, a.hideLink:hover {
      border-bottom: 1px dotted #36f; }
</style>



<div id="wrap">
<a href="#" id="example-show" class="showLink" onclick="showHide('example');">
<button class="btn-u btn-u-lg btn-block btn-u-dark-orange">
Read More
</button>
</a>
<div id="example" class="more">
<iframe width="600" height="315" src="//www.youtube.com/embed/BaPlMMlyM_0" frameborder="0" allowfullscreen></iframe>
<p>Congratulations! You've found the magic hidden text! Clicking the link below will hide this content again.</p>
</div>
</div>  

<!-- Hide Function -->           
<script language="javascript" type="text/javascript">
function showHide(shID) {
   if (document.getElementById(shID)) {
      if (document.getElementById(shID+'-show').style.display != 'none') {
         document.getElementById(shID+'-show').style.display = 'none';
         document.getElementById(shID).style.display = 'block';
      }
      else {
         document.getElementById(shID+'-show').style.display = 'inline';
         document.getElementById(shID).style.display = 'none';
      }
   }
}
</script>

您选择了错误的元素:shID+'-show' = 'example-show',这个 id 不是隐藏的 div。这是我认为你想要实现的工作版本。

function showHide(shID) {
  var hiddenDiv = document.getElementById(shID);
  if ( hiddenDiv ) {
    if (hiddenDiv.style.display !== 'none') {
      hiddenDiv.style.display = 'none';
    }
    else {
      hiddenDiv.style.display = 'inline';
    }
  }
}
/* This CSS is used for the Show/Hide functionality. */
.more {
  display: none;
  border-top: 1px solid #666;
  border-bottom: 1px solid #666; 
}
a.showLink, a.hideLink {
  text-decoration: none;
  color: #36f;
  padding-left: 8px;
  background: transparent url(down.gif) no-repeat left; 
}
a.hideLink {
  background: transparent url(up.gif) no-repeat left;
}
a.showLink:hover, a.hideLink:hover {
  border-bottom: 1px dotted #36f;
}
<div id="wrap">
  <a href="#" id="example-show" class="showLink" onclick="showHide('example');">
    <button class="btn-u btn-u-lg btn-block btn-u-dark-orange">
      Read More
    </button>
  </a>
  <div id="example" class="more">
    <iframe width="600" height="315" src="//www.youtube.com/embed/BaPlMMlyM_0" frameborder="0" allowfullscreen></iframe>
    <p>Congratulations! You've found the magic hidden text! Clicking the link below will hide this content again.</p>
  </div>
</div>