Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击选项卡后在确切的ID上滚动_Javascript_Tabs - Fatal编程技术网

Javascript 单击选项卡后在确切的ID上滚动

Javascript 单击选项卡后在确切的ID上滚动,javascript,tabs,Javascript,Tabs,我有以下选项卡代码,它是定制的: $(document).on('click', '#tabs li a', function () { var inst=$(this); window.location.hash = inst.attr('href'); $('#tabs li').each(function() { $(this).removeClass('active'); }) $('#tabs .tab').each(fun

我有以下选项卡代码,它是定制的:

$(document).on('click', '#tabs li a', function () {
    var inst=$(this);

    window.location.hash = inst.attr('href');

    $('#tabs li').each(function() {
        $(this).removeClass('active');
    })

    $('#tabs .tab').each(function() {
        $(this).removeClass('activetabs');
    })

    inst.parent().addClass('active');
    $(inst.attr('href')).addClass('activetabs');

    return false;
})

var aloved_hashes = [];
if ($('#tabs ul li a').html() != undefined) {
    $('#tabs ul li a').each (function() {
        aloved_hashes.push($(this).attr('href'));

    })
}

if (window.location.hash != '') {
    var hash = window.location.hash;

    if ($.inArray(hash, aloved_hashes) == -1) {

        window.location.hash = '';
    }

    $('#tabs li').each(function() {
        $(this).removeClass('active');
    })

    $('#tabs .tab').each(function() {
        $(this).removeClass('activetabs');
    })

    $('a[href="'+hash+'"]').parent().addClass('active')  
    $(hash).addClass('activetabs');
} 

不幸的是,google chrome开始变得凌乱,当我按下一个标签时,它总是滚动到ID,什么不应该做,有什么解决方案吗?我只是不想从中看到确切的ID。

嗯,为什么不;难道你不让浏览器跟随链接吗?你用视窗,位置,散列…嗯,你有什么建议吗?删除部分代码?