jquery垂直标签,跳到页面顶部,如何停止?

时间:2013-11-28 06:39:32

标签: javascript jquery

这是我的演示链接: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();
        }
    }
});

2 个答案:

答案 0 :(得分:0)

单击时必须处理href,将此代码添加到JS:

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

答案 1 :(得分:0)

我认为这会对你有所帮助:

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