jQuery-链接到ul.tabs之外的选项卡

jQuery-链接到ul.tabs之外的选项卡,jquery,html,html-lists,hyperlink,Jquery,Html,Html Lists,Hyperlink,如何更改下面的脚本,以便在ul.tabs之外创建指向不同选项卡的可单击链接 任何帮助都将不胜感激 <script type="text/javascript"> $(document).ready(function() { var $tabContent = $(".tab-content"), $tabs = $("ul.tabs li"), tabId; $tabContent.hide()

如何更改下面的脚本,以便在
ul.tabs
之外创建指向不同选项卡的可单击链接

任何帮助都将不胜感激

<script type="text/javascript">
    $(document).ready(function() {
        var $tabContent = $(".tab-content"),
            $tabs = $("ul.tabs li"),
            tabId;

        $tabContent.hide();
        $("ul.tabs li:first").addClass("active").show();
        $tabContent.first().show();

        $tabs.click(function() {
            var $this = $(this);
            $tabs.removeClass("active");
            $this.addClass("active");
            $tabContent.hide();
            var activeTab = $this.find("a").attr("href");
            $(activeTab).fadeIn();
            //return false;
        });

        // Grab the ID of the .tab-content that the hash is referring to
        tabId = $(window.location.hash).closest('.tab-content').attr('id');

        // Find the anchor element to "click", and click it
        $tabs.find('a[href=#' + tabId + ']').click();
    })

    $('a').not('.tabs li a').on('click', function(evt) {
        evt.preventDefault();
        var whereTo = $(this).attr('goto');
        $tabs = $("ul.tabs li");
        $tabs.find('a[href=#' + whereTo + ']').trigger('click');
        //alert(attr('name'));
    //alert( $('#'+whereTo+' a').offset().top );
        $('html, body').animate({
            scrollTop: $('#'+whereTo+' a').offset().top
        });

    });

    $(function() {
        $('a.refresh').live("click", function() {
            location.reload();
        });
    });
</script>

$(文档).ready(函数(){
var$tabContent=$(“.tab content”),
$tabs=$(“ul.tabs li”),
塔比德;
$tabContent.hide();
$(“ul.tabs li:first”).addClass(“active”).show();
$tabContent.first().show();
$tabs。单击(函数(){
var$this=$(this);
$tabs.removeClass(“活动”);
$this.addClass(“活动”);
$tabContent.hide();
var activeTab=$this.find(“a”).attr(“href”);
$(activeTab.fadeIn();
//返回false;
});
//获取哈希所引用的.tab内容的ID
tabId=$(window.location.hash).closest('.tab-content').attr('id');
//找到要“单击”的锚元素,然后单击它
$tabs.find('a[href=#'+tabId+'])。单击();
})
$('a')。非('tabs li a')。关于('click',函数(evt){
evt.preventDefault();
var whereTo=$(this.attr('goto');
$tabs=$(“ul.tabs li”);
$tabs.find('a[href=#'+whereTo+'])。trigger('click');
//警报(attr('name'));
//警报($('#'+whereTo+'a').offset().top);
$('html,body')。设置动画({
scrollTop:$(“#”+whereTo+“a”).offset().top
});
});
$(函数(){
$('a.refresh').live(“单击”,函数(){
location.reload();
});
});

代码来源:

它已经为您准备好了,只需指定与您要转到的选项卡的href相匹配的goto属性:

<a href="#" goto="my_tab">Clicky</a>

将转到设置为的选项卡

<ul class="tabs">
    <li><a href="#my_tab">It goes here</a></li>

恕我不敢苟同:)请查看最上面的链接,睡了一夜之后,我会在遵循您的JSFIDLE后让它工作,非常感谢Joe@乔-有可能防止跳转到内容的顶部吗?还有,需要链接哪些库?我在JSFIDLE中使用它,但在我的实际网站上没有。我只有jq1.10.1链接。谢谢@sloga你最好问一个新的问题,包括所有的细节——我不太确定你说的“跳到内容的顶端”是什么意思,没有代码看,我只是猜测