首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有多个div的每个函数jquery

具有多个div的每个函数jquery
EN

Stack Overflow用户
提问于 2014-08-13 14:33:41
回答 3查看 40关注 0票数 0

我有几个div和一个类“..intro”。在这些div中,我有按钮标记来触发类“..more”的div的上下滑动。如何对其进行编码,使其打开相关的“更多”div,而不是同时打开所有这些?

这是我到目前为止尝试过的jquery:

代码语言:javascript
复制
function answer() {
   $(".trigger").click(function () {
        if ($(".slider").hasClass("slideup"))
            $(".slider").removeClass("slideup").addClass("slidedown");
         else
            $(".slider").removeClass("slidedown").addClass("slideup");
        });
   }; 



$.each($(answer($('.intro'))));

我的HTML在这里:

代码语言:javascript
复制
 <div class="container">
      <div class="icon">
        <img src="images/tour-1.png" alt=""/>
    </div>
    <div class="intro">
      <button class="trigger">x</button>
      <h2>The gold standard</h2>
      <h3>Over 25 years training elite digital and direct marketers</h3>
      <div class="slider" class="slideup">
                <div class="more">
                   <p>Respected across the globe, we've awarded over 10,000 professional qualifications and trained 62,000 marketers on short courses. All IDM  digital marketing course content is continually reviewed and updated by a dedicated network of over 200 marketing practitioners.</p>
               </div>
           </div>
       </div>
   </div>
   <div class="container">
    <div class="icon">
        <img src="images/tour-6.png" alt=""/>
    </div>
    <div class="intro">
      <button class="trigger">x</button>
      <h2>Professional marketing qualifications for digital marketers</h2>
      <h3>The IDM is the UK's only government approved awarding body for direct and digital marketing</h3>
      <div class="slider" class="slideup">
                <div class="more">
                   <p>Choose from our range of digital marketing courses, depending on your level and field of interest. Independent proof of your expertise and               commitment.</p>
               </div>
           </div>
       </div>
   </div>
   <div class="container">
    <div class="icon">
        <img src="images/tour-5.png" alt=""/>
    </div>
    <div class="intro">
      <button class="trigger">x</button>
      <h2>Learn through technology</h2>
      <h3>Interactive and engaging content in the palm of your hand</h3>
      <div class="slider" class="slideup">
                <div class="more">
                   <p>We're passionate about bringing together the latest learning technology and expert digital marketing knowledge in a virtual campus full of               learning resources</p>
               </div>
           </div>
       </div>
   </div>

http://jsfiddle.net/isherwood/4xym8evp/

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-08-13 14:40:12

http://jsfiddle.net/isherwood/4xym8evp/2/

代码语言:javascript
复制
$('.trigger').click(function () {
    $(this).siblings('.slider').find('.more').slideToggle();
});
票数 2
EN

Stack Overflow用户

发布于 2014-08-13 14:42:50

如果我理解了,您希望在div '.intro‘内滑动类’.intro‘的div,并触发按钮。

代码语言:javascript
复制
$(".trigger").click(function () {
    var slider = $(this).parent().find('.slider');
    if (slider.hasClass("slideup"))
        slider.removeClass("slideup").addClass("slidedown");
     else
        slider.removeClass("slidedown").addClass("slideup");
    });
};
票数 0
EN

Stack Overflow用户

发布于 2014-08-13 14:45:16

这是你想要的吗?

代码语言:javascript
复制
$(document).ready(function(){
    $(".trigger").click(function(){
        $(this).siblings(".slider").find(".more").slideToggle();
    });
});

小提琴

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25288974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档