我已经在这几天苦苦挣扎,我已经彻底搜索了一个没有尽头的答案,但还没有找到任何答案。我正在使用的脚本位于:http://www.adipalaz.com/experiments/jquery/nested_accordion.html 项目本身就在这里: http://primefooddistributor.com/about.htm
基本上我想要完成的是将侧面导航链接到特定页面(在本例中为about.htm)并在页面加载时打开手风琴的相应面板。这是标记:
<!-- ********************* Accordion ********************* -->
<ul id="acc1" class="accordion hidden" style="list-style-type:none">
<li>
<h2 class="header">Our Story</h2>
<div class="inner">
<ul style="list-style-type:none">
<li>
<h3 class="header" id="test">Stand Alone: PFD is a different kind of company.</h3>
<div class="inner">
<p align="justify" class="bodytext"></p>
</div>
</li>
<li>
<h3 class="header">Ambassadors:</h3>
<div class="inner">
<p align="justify"></p>
</div>
</li>
<li>
<h3 class="header">Tradition:</h3>
<div class="inner">
<p align="justify">.</p>
</div>
</li>
</ul>
</div>
</li>
<li>
<h2 class="header">Family Tree</h2>
<div class="inner">
<ul style="list-style-type:none">
<li>
<h3 class="header">Corporate Officers</h3>
<div class="inner">
<p>
</p>
</div>
</li>
<li>
<h3 class="header">PFD Team</h3>
<div class="inner">
<p>
</p>
</div>
</li>
<li>
<div class="inner">
</div>
</li>
</ul>
</div>
</li>
<li>
<h2 class="header">Generations In Our Industry</h2>
<div class="inner">
<ul style="list-style-type:none">
<li>
<h3 class="header">The true definition of tradition ...</h3>
<div class="inner">
<p>
</p>
</div>
</li>
<li>
<div class="inner">
</div>
</li>
<li>
<div class="inner">
</div>
</li>
</ul>
</div>
</li>
<li>
<h2 class="header">My Story</h2>
<div class="inner">
<ul style="list-style-type:none">
<li>
<h3 class="header">The art of butchery requires two things:</h3>
<div class="inner">
<p>
</p>
</div>
</li>
<li>
<div class="inner">
</div>
</li>
<li>
<div class="inner">
</div>
</li>
</ul>
</div>
</li>
</ul> <!-- end accordion -->
这是jQuery Call:
$(document).ready("html").addClass("js");
$.fn.accordion.defaults.container = false;
$(document).ready(function() {
$("#acc1").accordion({
el: ".h",
head: "h2, h3",
next: "div"
});
$("html").removeClass("js");
});
我现在正在尝试查看从导航链接传递的URL哈希,将哈希设置为变量并使用该变量按ID查找元素并向该元素添加一个类。这是我到目前为止所做的,但它不适合我:
<script type="text/javascript">
if(window.location.hash) {
var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
$(document).ready.getElementById(hash).addClass("open");
// hash found
} else {
// No hash found
}
</script>
任何帮助将不胜感激!谢谢!
答案 0 :(得分:0)
这是我以前做过的事情:
http://jsfiddle.net/volterony/z333M/
我知道你引用了这个块,但我认为我的例子可能会为你做这个工作吗?
$(document).ready("html").addClass("js");
$.fn.accordion.defaults.container = false;
$(document).ready(function() {
$("#acc1").accordion({
el: ".h",
head: "h2, h3",
next: "div"
});
$("html").removeClass("js");
});
希望它对你有用。
Volterony