简体   繁体   English

了解jQuery父母与子女

[英]understanding jQuery parent and children

I am trying to make sense of jquery and have hit a brick wall. 我试图使jquery的意义,并撞墙。 I have a created a drop down show and hide menu function [Click here][1] However i can not get it to work correctly. 我创建了一个下拉显示和隐藏菜单功能[单击此处] [1],但是我无法使其正常工作。 On the right hand side of the page where you see about, delivery etc. I am trying to create a function where when the user clicks on one of the tabs it hides the tab that has the class .active and add the class the next li . 在页面的右侧,您可以看到有关交付的信息。我试图创建一个函数,当用户单击其中一个选项卡时,它会隐藏具有.active类的选项卡,并在下一个li添加该类。 For some reason my script is not working. 由于某种原因,我的脚本无法正常工作。 Does anyone know why? 有人知道为什么吗?

$('.hidden-bits').removeClass('active');
    $('.hidden-bits').eq(0).addClass('active');

    $('.accordin-link').click(function(){
        var $this = $(this);
        $('.hidden-bits').slideUp().removeClass('active');
        $this.parent()('.hidden-bits').slideDown().addClass('active');
    });

HTML 的HTML

<ul id="product-info">
    <li>
        <span>
            <a class="accordin-link" href="#">about</a>
        </span>
          <ul class="hidden-bits">
            <li>
                <div class="tab">
                    <div class="productDesc">
                        Lorem ipsum dolor sit amet, consectetur adipisicing elit, labore et dolore magna aliqua Lorem ipsum dolor sit amet, consectetur adipisicing elit, labore et dolore magna aliqua Lorem ipsum dolor sit amet, consectetur adipisicing elit, labore et dolore magna aliqua.
                    </div>
                </div>
            </li>
        </ul>
    </li>

.hidden-bits{
    display: none;
}

.active{
    display: block;
}

You need to do this - 您需要这样做-

$('.accordin-link').click(function(){
    var $this = $(this);
    $('.hidden-bits').slideUp().removeClass('active');
    $this.parent().next('.hidden-bits').slideDown().addClass('active');
});

Demo ---> http://jsfiddle.net/HhMjn/ 演示---> http://jsfiddle.net/HhMjn/

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

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