jquery - 将选项卡外的元素与选项卡项关联

标签 jquery

我有一个可以运行的选项卡脚本:

http://jsfiddle.net/fmqeh/8/

单击“.tab”项目后,ul.tab li 项目的类别为“actives”。但是点击

<a class="bdn" href="#tab2">Go to Tab 2</a>

<a class="bdn">无法添加class="actives选项卡项目。我怎样才能通过滚动到

来做到这一点
<div class="tab_content chart" id="tab2">
    this is the content of tab2
</div>

提前致谢

最佳答案

如果您只需在要激活的选项卡上触发点击事件,就会容易得多:

$(".bdn").click(function(e) {
    var $tabs = $('ul.tab');
    $tabs.find('a[href="#tab2"]').click();
    $(window).scrollTop($tabs.offset().top);
    e.preventDefault();
});

您的固定演示:http://jsfiddle.net/fmqeh/11/

关于jquery - 将选项卡外的元素与选项卡项关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6168227/

相关文章:

javascript - Jquery在页面上查找div

jquery动画并使div居中

javascript - 在媒体查询中调用/触发 Foundation JS

用于查找字符串的 jquery 选择器

javascript - jQuery 平滑滚动问题

javascript - img onclick 不起作用

javascript - 在包含 html 代码 jquery 的变量中更改 Id & Class

jquery - 如何知道我点击了哪个 div 来更改它的内容?

javascript - 如何使用 jquery/javascript && 重置 html 中的表单数据以及如何使用 jquery 将表单数据发送到电子邮件?

javascript - Bootstrap : popover button link not working