jquery 选项卡 - 我无法制作我的
  • ;可点击的
  • 发布于 2024-12-21 23:20:08 字数 1517 浏览 3 评论 0原文

    这是我的选项卡式界面,我有一个 jsfiddle 这里

    <div class="tabs">
      <!-- tabs -->
      <ul class="tabNavigation">
        <li><a href="#corporations">Corporations</a></li>
        <li><a href="#non-profit">non-profit</a></li>
        <li><a href="#growing-businesses">growing-businesses</a></li>
        <li><a href="#arrange">Arrange a meetup</a></li>
      </ul>
    
      <!-- tab containers -->
      <div id="corporations">
        <p>Lorem ipsum dolor sit amet.</p>
      </div>
      <div id="non-profit">
        <p>Sed do eiusmod tempor incididunt.</p>
      </div>
      <div id="growing-businesses">
        <p>Ut enim ad minim veniam</p>
      </div>
      <div id="arrange">
        <p>Sed do ad minim ipsum dolor sit</p>
      </div>
    </div>
    

    这是我的jquery,它很简单。

    $(function () {
        var tabContainers = $('div.tabs > div');
    
        $('div.tabs ul.tabNavigation a').click(function () {
            tabContainers.hide().filter(this.hash).show();
    
            $('div.tabs ul.tabNavigation a').removeClass('selected');
            $(this).addClass('selected');
    
            return false;
        }).filter(':first').click();
    });
    

    我的问题是我知道如何轻松操作 以便更改悬停或单击时的内容,我已经在 jsfiddle 中完成了这一点。但我想将鼠标悬停或单击

  • 并更改容器中要显示的信息。
  • This is my tabbed interface, I have a jsfiddle here.

    <div class="tabs">
      <!-- tabs -->
      <ul class="tabNavigation">
        <li><a href="#corporations">Corporations</a></li>
        <li><a href="#non-profit">non-profit</a></li>
        <li><a href="#growing-businesses">growing-businesses</a></li>
        <li><a href="#arrange">Arrange a meetup</a></li>
      </ul>
    
      <!-- tab containers -->
      <div id="corporations">
        <p>Lorem ipsum dolor sit amet.</p>
      </div>
      <div id="non-profit">
        <p>Sed do eiusmod tempor incididunt.</p>
      </div>
      <div id="growing-businesses">
        <p>Ut enim ad minim veniam</p>
      </div>
      <div id="arrange">
        <p>Sed do ad minim ipsum dolor sit</p>
      </div>
    </div>
    

    This is my jquery which is simple enough.

    $(function () {
        var tabContainers = $('div.tabs > div');
    
        $('div.tabs ul.tabNavigation a').click(function () {
            tabContainers.hide().filter(this.hash).show();
    
            $('div.tabs ul.tabNavigation a').removeClass('selected');
            $(this).addClass('selected');
    
            return false;
        }).filter(':first').click();
    });
    

    My problem is I know how to easily manipulate an <a> in order to change the contents on hover or click, which I have already done in the jsfiddle. But I want to hover or click the <li> and change the information in the container to show.

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    宁愿没拥抱 2024-12-28 23:20:09

    您需要做的就是选择

  • 元素并绑定 click 事件处理程序,就像链接一样:
  • $(function () {
        var tabContainers = $('div.tabs > div');
    
        //here I am targeting the `<li>` elements instead of the `<a>` elements
        $('div.tabs ul.tabNavigation li').click(function () {
    
            //to get the "hash" you need to select the child `<a>` element of this `<li>` element
            var the_hash = $(this).children().attr('href');
            tabContainers.hide().filter(the_hash).show();
    
            //and here the `selected` class is being added and removed from the `<li>` elements rather than the `<a>` elements
            $('div.tabs ul.tabNavigation li').removeClass('selected');
            $(this).addClass('selected');
    
            return false;
        }).filter(':first').click();
    });
    

    这是 jsfiddle 的更新版本: http://jsfiddle.net/3EyCT/5/

    All you need to do is select the <li> elements and bind a click event handler, just the same as for a link:

    $(function () {
        var tabContainers = $('div.tabs > div');
    
        //here I am targeting the `<li>` elements instead of the `<a>` elements
        $('div.tabs ul.tabNavigation li').click(function () {
    
            //to get the "hash" you need to select the child `<a>` element of this `<li>` element
            var the_hash = $(this).children().attr('href');
            tabContainers.hide().filter(the_hash).show();
    
            //and here the `selected` class is being added and removed from the `<li>` elements rather than the `<a>` elements
            $('div.tabs ul.tabNavigation li').removeClass('selected');
            $(this).addClass('selected');
    
            return false;
        }).filter(':first').click();
    });
    

    Here is an updated version of your jsfiddle: http://jsfiddle.net/3EyCT/5/

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文