簡體   English   中英

jQuery垂直標簽,跳到頁面頂部,如何停止?

[英]jquery vertical tab, jumping to top of the page, how to stop?

這是我的演示鏈接: http : //www.bajistech.info/tiltindicators.html

我必須為每個標簽創建特定的鏈接

 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() {

//不需要每個循環$('ul#verticalNav li a')。click(function(){

            showSection( $(this).attr('href') );
        });
        //});
        if(window.location.hash) 
        // if hash found then load the tab from Hash id
        {
           showSection( window.location.hash);// to get the div id
        }
        else // if no hash found then default first tab is opened
        {
            $('ul#verticalNav li:first-child a').click();
        }
    }
});

您必須在單擊時處理href,然后將此代碼添加到您的JS中:

$("#verticalNav li a").click(function(event) { event.preventDefault()});

我認為這將幫助您:

$('ul#verticalNav li a').click(function(){
return false;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM