Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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单击垂直选项卡时,如何显示页面标题和菜单_Javascript_Jquery - Fatal编程技术网

当我们使用javascript单击垂直选项卡时,如何显示页面标题和菜单

当我们使用javascript单击垂直选项卡时,如何显示页面标题和菜单,javascript,jquery,Javascript,Jquery,垂直选项卡使用javascript。垂直选项卡工作正常,但我无法看到页面标题和菜单部分,当我单击选项卡时,只有我可以看到div信息。 标题 HTML: 它正在跳转到id 这是锚点的href中的散列的默认行为 $('ul#verticalNav li a').click(function() { showSection( $(this).attr('href') ); }); 应该是这样的: $('ul#verticalNav a').click(function(e) { w

垂直选项卡使用javascript。垂直选项卡工作正常,但我无法看到页面标题和菜单部分,当我单击选项卡时,只有我可以看到div信息。 标题

HTML:
它正在跳转到
id

这是
锚点的
href
中的
散列的默认行为

$('ul#verticalNav li a').click(function() { 
    showSection( $(this).attr('href') );
});
应该是这样的:

$('ul#verticalNav a').click(function(e) {
    window.location.hash = $(this).attr('href');//update hash manually
    showSection(window.location.hash);//with newly updated hash
    //no jumping :: added both to make more browser compatible
    e.preventDefault();
    return false;
});
大局

这可能更易于维护,并修复了其他问题

var vn = $('#verticalNav a'), ss = $('.section');//get elements

function showSection(sectionID) {
    $(sectionID).show().siblings().hide();//show current & hide siblings
}

if (vn.length && ss.length) {//if parts
    ss.hide();//hide sections
    vn.click(function(e) {//on tab click
        window.location.hash = $(this).attr('href');//update hash manually
        $(this).parent().addClass('on').siblings('.on').removeClass('on');//toggle active
        showSection(window.location.hash);//with newly updated hash
        e.preventDefault();//prevent default behavior
        return false;//return false
    });
    if (window.location.hash) {//if hash
        $('html, body').scrollTop(0);//no jump
        showSection(window.location.hash);//show slide
    } else {
        ss.eq(0).show();//show first slide
        vn.eq(0).parent().addClass('on');//make first tab active
    }
}

做了一个调子:

你好,谢谢,现在工作正常,但不显示下面的链接,如带有#id的url等。谢谢。你好,非常感谢你,现在工作很好,但是当我点击页面直接呼叫第一个id时,我犯了什么错误。谢谢。看起来像
$('ul#verticalNav li:first child a')。单击()
正在触发click事件并在加载时更新哈希。将其替换为类似
$('.section').eq(0.show()
应该显示第一张幻灯片,并且应该可以正常工作。您可能还需要添加类似于
$('html,body')的内容。scrollTop(0)
$('div.section').css('display','none')之前
以防止加载时出现哈希时页面加载跳转。
ss=$('.section')
,但很高兴我能提供帮助!
$('ul#verticalNav li a').click(function() { 
    showSection( $(this).attr('href') );
});
$('ul#verticalNav a').click(function(e) {
    window.location.hash = $(this).attr('href');//update hash manually
    showSection(window.location.hash);//with newly updated hash
    //no jumping :: added both to make more browser compatible
    e.preventDefault();
    return false;
});
var vn = $('#verticalNav a'), ss = $('.section');//get elements

function showSection(sectionID) {
    $(sectionID).show().siblings().hide();//show current & hide siblings
}

if (vn.length && ss.length) {//if parts
    ss.hide();//hide sections
    vn.click(function(e) {//on tab click
        window.location.hash = $(this).attr('href');//update hash manually
        $(this).parent().addClass('on').siblings('.on').removeClass('on');//toggle active
        showSection(window.location.hash);//with newly updated hash
        e.preventDefault();//prevent default behavior
        return false;//return false
    });
    if (window.location.hash) {//if hash
        $('html, body').scrollTop(0);//no jump
        showSection(window.location.hash);//show slide
    } else {
        ss.eq(0).show();//show first slide
        vn.eq(0).parent().addClass('on');//make first tab active
    }
}