简体   繁体   English

单击时会显示jQuery选项卡和选项卡内容吗?

[英]jQuery tab and tab content show up when clicked ?

My webpage is at http://www.sarahjanetrading.com/js/resume 我的网页是http://www.sarahjanetrading.com/js/resume

All the HTML, CSS and jQuery code + images are available there for anyone to access. 所有HTML,CSS和jQuery代码+图像都可供任何人访问。

My issue is that currently my jQuery code makes the tabs show the tab-content when I click on the achor tag of the tab. 我的问题是,当我点击选项卡的achor标签时,目前我的jQuery代码使标签显示标签内容。 But the tab doesnt change into the clicked tab.(tab name remains the same). 但是选项卡不会更改为单击的选项卡。(选项卡名称保持不变)。

And the tab changes into the clicked tab when i click on the respective li of the tab. 当我单击选项卡的相应li时,选项卡将更改为单击的选项卡。 What I want is that both the tab changes and the content of the tab shows when I click on the either the li of the tab or the anchor of the tab. 我想要的是当我单击选项卡的li或选项卡的锚点时,选项卡更改和选项卡的内容都会显示。

You have two lots of events registered. 您注册了两个活动。 One on the anchors and the other on the lis. 一个在锚上,另一个在lis上。 The one on the lis changes the active state for the tabs themselves while the one on the anchors change the content. lis上的那个更改了标签本身的活动状态,而锚点上的那个更改了内容。 You should combine these into one function. 您应该将这些组合成一个功能。

You change check the li function is working by clicking on the very bottom edge of it. 您可以通过单击它的最下边缘来更改检查li功能是否正常工作。 Because your anchor javascript has a return false feclaration it is preventing the click event bubbling up to the li, thus not showing the change. 因为你的锚javascript有一个return false声明,它阻止了点击事件冒泡到li,因此没有显示更改。

Try changing the function: 尝试更改功能:

 $("ul.tabs li a").click(function() {
        $("ul.tabs li > a").removeClass("active");
        $(this).addClass("active");
        $("#wrap > div").hide();
        var activeTab = $(this).attr("href");
        $(activeTab).show();
        return false;
    });

to the following: 以下内容:

 $("ul.tabs li a").click(function() {
        $(".active").removeClass("active");
        $(this).addClass("active");
        $("#wrap > div").hide();
        $(".active-tab").removeClass();
        $(this).parent().addClass("active-tab");
        var activeTab = $(this).attr("href");
        $(activeTab).show();
        return false;
    });

This should work and you should be able to remove your other javascript function. 这应该工作,你应该能够删除你的其他JavaScript功能。

If you already use jQuery you can use the jQueryUI library to create tabs. 如果您已经使用jQuery,则可以使用jQueryUI库来创建选项卡。 It is very simple and the style can easily be changed. 它非常简单,风格很容易改变。 Here is the Tutorial for tabs: 这是选项卡的教程:

jQuery UI - Tabs Demo jQuery UI - 选项卡演示

If you click the whitespace around the text in the tabs, it works. 如果单击选项卡中文本周围的空白,则可以正常工作。 Remove the anchor link from inside the tab, or add a click handler for the anchor link. 从选项卡内部删除锚链接,或为锚链接添加单击处理程序。

Edit: 编辑:
My mistake. 我的错。 You have a click handler on your anchor element, but clicking the anchor link causes it to become $(this) in your code. 您的anchor元素上有一个单击处理程序,但单击anchor链接会使其在代码中变为$(this) So you assign class="active" to the anchor , when you want to assign it to the li . 因此,当您要将其分配给li时,将class="active"分配给anchor

$(this).addClass("active");

should be rewritten to modify the li . 应该重写以修改li Personally, I would wrap the li in the anchor link: 就个人而言,我会将li包装在锚链接中:

<a href="#something"><li></li></a>

This will probably require modifying your JS code a little, but will give a uniform result. 这可能需要稍微修改一下JS代码,但会得到统一的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM