function showSection(sectionID) {
$('div.section').css('display', 'none');
$('div'+sectionID).css('display', 'block');
}
$(document).ready(function(){
if (
$('ul#verticalNav li a').length &&
$('div.section').length
) {
$('div.section').css('display', 'none');
$('ul#verticalNav li a').each(function() {
$(this).click(function() {
showSection($(this).attr('href'));
});
});
$('ul#verticalNav li:first-child a').click();
}
});
<ul id="verticalNav">
<li><a href="#section1">Section I</a></li>
<li><a href="#section2">Section II</a></li>
<li><a href="#section3">Section III</a></li>
</ul>
<div id="sections">
<div class="section" id="section1">
<p>Some content specific to this section...</p>
</div>
<div class="section" id="section2">
<img src="#" alt="BADGER" />
</div>
<div class="section" id="section3">
<img src="#g" alt="SNAKE" />
</div>
</div>
我要創建特定鏈接的index.html#SECTION1每個標籤例如,index.html的#2節如何創建指向特定標籤的鏈接? (jQuery的)
問題是什麼?什麼不行?它應該如何工作? – matewka
在你提供的頁面中,一切正常。當你點擊鏈接時,它會隱藏所有部分,並顯示鏈接中指定的部分。然後,默認鏈接行爲導航到該部分的頂部。你是否想要__not__導航,但只顯示該部分? – matewka
嗨matewka,我如何顯示默認部分。 – user2913707