我在這裏有兩個頁面:索引和結果。在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