javascript - 在 jquery 垂直选项卡中单击不同选项卡时如何停止页面转到顶部

标签 javascript jquery html css

此处示例:http://www.bajistech.info/tiltindicators.html#TiltWatch-Plus1

完整代码:

$(文档).ready(函数(){

    if (
        $('ul#verticalNav li a').length &&
        $('div.section').length
    ) {
        $('div.section').css( 'display', 'none' );
        //$('ul#verticalNav li a').each(function() { // no need for each loop
        $('ul#verticalNav li a').click(function() { // Use $('ul#verticalNav li a').click
            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();
        }
    }
});

最佳答案

您描述的“转到顶部”行为通常是由损坏的主题标签链接引起的,例如:

<a href="#nonExistingId">link</a>

或者只是

<a href="#">link</a>

关于您发布的代码:我不知道您为什么需要它。

查看 http://jqueryui.com/tabs/#vertical 中的示例,然后单击查看源代码。如果您正确实例化选项卡小部件,例如

$("#idOfMyTabElement").tabs();

并且您确保选项卡元素中的链接指向有效的 div(如示例中所示),那么您应该没问题。

关于javascript - 在 jquery 垂直选项卡中单击不同选项卡时如何停止页面转到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20062392/

相关文章:

javascript - 对象层次结构中的变量范围

javascript - 将带有 Promise 的函数从 JS 转换为 TS 时出现问题

带有多个下拉菜单的 jQuery ajax 调用

python - 如何从html中提取一些url?

javascript - 为什么我无法使用 jquery 设置 div 的 z-index?

javascript - 作为自身父对象的 javascript 对象?

javascript - 在 React.js 中实现阅读更多链接

jquery - PUT jQuery 的问题

javascript - Swiper slider 无法按预期使用循环 : true and centeredSlides: false

javascript - jQuery slideDown,不处理链接