Javascript JQuery HidealShowOne+;打开DIV的链接
我仅使用HidealShowOne使用此JQuery:Javascript JQuery HidealShowOne+;打开DIV的链接,javascript,jquery,html,Javascript,Jquery,Html,我仅使用HidealShowOne使用此JQuery: <script type="text/javascript" language="JavaScript"><!-- function HideContent(d) { document.getElementById(d).style.display = "none"; } function ShowContent(d) { document.getElementById(d).style.display = "block"
<script type="text/javascript" language="JavaScript"><!--
function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function HideAllShowOne(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}
function HideAllShowOne(d) {
// Between the quotation marks, list the id values of each div.
var IDvaluesOfEachDiv = "1 2 3 4 5 6 7 8 9 10 11 12 13 14";
//-------------------------------------------------------------
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/[,\s"']/g," ");
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/^\s*/,"");
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/\s*$/,"");
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/ +/g," ");
var IDlist = IDvaluesOfEachDiv.split(" ");
for(var i=0; i<IDlist.length; i++) { HideContent(IDlist[i]); }
ShowContent(d);
}
//--></script>
使用此HTML
<div class="heading marg_none">
<h5><a href="javascript:HideAllShowOne('2')">Step 2. Adding Services</a></h5>
</div>
<div id="2" style="display: none;">
<p>
Watch the video for full details.
</p>
</div>
观看视频了解全部细节。
这对于在我的网站上打开FAQ样式页面中的每个部分都很好,但是我希望能够从网站上的其他地方链接到每个问题,并让它自动滚动到该分区并打开它。这可能吗
谢谢。url必须如下:(对于第一个问题)哈希显示这是第一个问题。您可以检查此代码下面的URL上是否有任何哈希:
if(window.location.hash) {
// Has exist
} else {
// Hash doesn't exist
}
var url = "http://www.aaa.com/faq#1";
var hash = url.substring(url.indexOf("#")+1);
然后您应该从下面的URL获取哈希代码:
if(window.location.hash) {
// Has exist
} else {
// Hash doesn't exist
}
var url = "http://www.aaa.com/faq#1";
var hash = url.substring(url.indexOf("#")+1);
在本例中,此哈希值应为“1”。最后一步是滚动到div:
window.location.hash = hash;
所以你想点击一个链接将你带到一个新页面,并让它在加载时向下滚动到某个部分?谢谢,我不确定这是否有效。虽然我可能在某个地方做错了什么。如果你从页面外重定向到散列url,示例应该可以工作