我在这里有两个页面:索引和结果。在results.html中,我有一些CSS属性设置为display:none的div。我想从索引(导航菜单)导航并打开结果页面,同时显示隐藏的div。 jQuery对results.html工作正常,但我不知道如何触发来自索引的此函数。jQuery导航到另一个页面并显示div隐藏
指数:
<ul>
<li><a id="menu-2016" href="results.html#2016">2016</a></li>
<li><a id="menu-2015" href="results.html#2015">2015</a></li>
</ul>
结果:
<section id="2016">Content</section>
<section id="2015">Content</section>
CSS:
#section-2015, #section-2016 {
display: none;
}
的jQuery:
$(document).ready(function() {
$("#menu-2016").click(function() {
$("#section-2016").slideDown();
$("#section-2015").slideUp();
});
$("#menu-2015").click(function() {
$("#section-2015").slideDown();
$("#section-2014").slideUp();
});
});
搜索关于'window.hash'和事件'window.onhashchange' 。这将是你轻松的解决方案。 –
什么是$(“#section-2016”)?您没有此ID的元素 –
@DarrenSweeney键入时出错。 – h1ghland3r