导航到另一个页面,在那里显示书签/id,同时隐藏其他

Navigation to another page and showing a bookmark/id there, while hiding others

本文关键字:id 其他 隐藏 书签 显示 另一个 在那里 导航      更新时间:2023-09-26

我使用以下代码来显示一些隐藏的Bootstrap wells在同一页面上,当一个菜单项被点击(像选项卡内容淋浴的工作)。它的工作很好,但我希望能够使用它去其他页面,并显示一个好(基于id属性那里。它不是这样工作的,请帮忙。

$(document).ready(function()
{
    var navItems = $('.menu-level-2 li > a');
    var navListItems = $('.menu-level-2 li');
    var allWells = $('.menu-level-2-content');
    var allWellsExceptFirst = $('.menu-level-2-content:not(:first)');
    allWellsExceptFirst.hide();
    navItems.click(function(e)
    {
        e.preventDefault();
        navListItems.removeClass('active');
        $(this).closest('li').addClass('active');
        allWells.hide();
        var target = $(this).attr('data-target-id');
        $('#' + target).show();
    });
});

这个问题对我来说不是很清楚,但是如果你想去另一个页面(当点击导航时),并且在另一个页面上,你想自动显示选项卡内容,那么你应该这样做:

navItems.click(function(e)
{
    ..........
    var target = $(this).attr('data-target-id');
    window.location='http://example.com/mypage.php#requested_id='+target;
});

和目标上的mypage.php,你应该有javascript:

$(document).ready(function()
{
    if (window.location.hash){
       .....
       allWells.hide();
       $('#' + window.location.hash).show();
    }
}
相关文章: