从一个页面链接到另一个页面并切换隐藏的div

时间:2016-08-23 15:03:19

标签: javascript wordpress

我有一个wordpress页面,其中包含指向帖子各部分的链接。

页:

<p><a href="http://204.128.208.7/link-test/#show1">Test 1</a></p>
<p><a href="http://204.128.208.7/link-test/#show2">Test 2</a></p>
<p><a href="http://204.128.208.7/link-test/#show3">Test 3</a></p>
<p><a href="http://204.128.208.7/link-test/#show4">Test 4</a></p>

发表:

<h4 id="show1" onclick="toggle('activeTransfers')">How to View Active Transfers<a id="arrowactiveTransfers">&#x25bc;</a></h4>
<div id="activeTransfers" style="display: none">
<p style="margin-left: 2em; margin-bottom: .5em">...</p>
<h4 onclick="toggle('activeTransfers')">Hide -</h4>
</div>
<p style="margin-bottom: 2em"> </p>
<h4 style="margin-bottom: .3em">Why an Item Is Not Included in the Automated Transfers</h4>
<p>The following are the main things that will keep an item off auto-transfers:</p>
<h4 id="show2" onclick="toggle('inventoryMasterMaintenance')">Inventory Master Maintenance<a id="arrowinventoryMasterMaintenance">&#x25bc;</a></h4>
<div id="inventoryMasterMaintenance" style="display: none;">
<p style="margin-left: 2em; margin-bottom: .5em">...</p>
<h4 onclick="toggle('inventoryMasterMaintenance')">Hide -</h4>
</div>
<p style="margin-bottom: 2em"> </p>
<h4 id="show3" onclick="toggle('vendorMaintenance')">Vendor Maintenance<a id="arrowvendorMaintenance">&#x25bc;</a></h4>
<div id="vendorMaintenance" style="display: none;">
<p style="margin-left: 2em; margin-bottom: .5em">...</p>
<h4 onclick="toggle('vendorMaintenance')">Hide -</h4>
</div>
<p style="margin-bottom: 2em"> </p>
<h4 id="show4" onclick="toggle('inventoryPriceMaintenance')">Inventory Price Maintenance<a id="arrowinventoryPriceMaintenance">&#x25bc;</a></h4>
<div id="inventoryPriceMaintenance" style="display: none;">
<p style="margin-left: 2em; margin-bottom: .5em">...</p>
<h4 onclick="toggle('inventoryPriceMaintenance')">Hide -</h4>
</div>

最近我做了所以我可以使用下面的代码切换长篇文章。

function toggle(id) {
 var element = document.getElementById(id);
 var text = document.getElementById("arrow" + id);
  if (element) {
  var display = element.style.display;

  if (display == "none") {
  element.style.display = "block";
  text.innerHTML = "&#9650;";

  } else {
  element.style.display = "none";
  text.innerHTML = "&#x25bc;";
  }
 }
}

但是现在当我使用从页面到帖子的链接时,它只显示部分标题。如果链接也打开了部分,我想要它。

我不知道如何实现这一点,或者甚至是否可能;有人可以帮帮我吗?

0 个答案:

没有答案