简体   繁体   English

单击当前元素时jQuery添加信息

[英]jQuery adding info when click current element

Lost my last account so I must create new but again Hi for all. 丢失了我的上一个帐户,因此我必须为所有帐户创建新帐户,但再次请输入Hi。

I have list of 6 divs, one like this: 我有6个div的列表,其中一个是这样的:

<figure id="trener_1">
          <img class="img-responsive center" src="<?php bloginfo('template_directory'); ?>/img/ex_wybierz_trenera1.jpg" alt="">
          <figcaption>
            <h4>Kasia Kowalska</h4>
          </figcaption>
          <a><div class="click_to text-center">
            <i class="fa fa-plus"></i>
            <p>Kliknij aby wybrać trenera</p>
          </div></a>
        </figure>
        <section class="row">
          <div class="col-sm-6 xs-p-top">
            <div class="choose_info trener_1" style="display:none;">
              <img class="pull-left" src="<?php bloginfo('template_directory'); ?>/img/check_trener.png" alt="">
              <p class="pull-left small-m-left xs-m-top text-bold">Wybrano trenera</p>
            </div>
          </div>
          <div class="col-sm-6">
            <a href="szczegoly-trenera" target="_blank"><h3 class="btn-custom_bg pull-right">Zobacz profil trenera</h3></a>
          </div>
        </section>

And when clicking on figure with specific id, the element with the same class show. 当单击具有特定ID的图形时,将显示具有相同类的元素。 Now I have six elements like this (trener_2, trener_3 etc..) and I want when I choose one --> info shows. 现在,我有六个这样的元素(trener_2,trener_3等。),当我选择一个->信息显示时,我想要。 But when I click another ex. 但当我点击另一个前。 trener_2 info with class trener_2 shows but from trener_1 disappear. 显示了带有trener_2类的trener_2信息,但从trener_1中消失了。

My js: 我的js:

$(function() {
            $('figure').click(function() {
                $("." + $(this).attr('id')).fadeIn('slow').siblings().hide();
            });
        });

Sorry for my bad English, any suggest will be very helpful. 对不起,我的英语不好,任何建议都将非常有帮助。

You can hide all the choose_info elements except the current one so 您可以隐藏除当前元素之外的所有choose_info元素,因此

 $(function() { $('figure').click(function() { var $t = $("." + $(this).attr('id')).fadeIn('slow'); $t.siblings().hide(); $('.choose_info').not($t).hide().siblings().show() }); }); 
 .choose_info { background-color: lightgrey; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <figure id="trener_1"> <img class="img-responsive center" src="<?php bloginfo('template_directory'); ?>/img/ex_wybierz_trenera1.jpg" alt=""> <figcaption> <h4>Kasia Kowalska</h4> </figcaption> <a> <div class="click_to text-center"> <i class="fa fa-plus"></i> <p>Kliknij aby wybrać trenera</p> </div> </a> </figure> <section class="row"> <div class="col-sm-6 xs-p-top"> <div class="choose_info trener_1" style="display:none;"> <img class="pull-left" src="<?php bloginfo('template_directory'); ?>/img/check_trener.png" alt=""> <p class="pull-left small-m-left xs-m-top text-bold">Wybrano trenera</p> </div> </div> <div class="col-sm-6"> <a href="szczegoly-trenera" target="_blank"><h3 class="btn-custom_bg pull-right">Zobacz profil trenera</h3></a> </div> </section> <figure id="trener_2"> <img class="img-responsive center" src="<?php bloginfo('template_directory'); ?>/img/ex_wybierz_trenera1.jpg" alt=""> <figcaption> <h4>Kasia Kowalska</h4> </figcaption> <a> <div class="click_to text-center"> <i class="fa fa-plus"></i> <p>Kliknij aby wybrać trenera</p> </div> </a> </figure> <section class="row"> <div class="col-sm-6 xs-p-top"> <div class="choose_info trener_2" style="display:none;"> <img class="pull-left" src="<?php bloginfo('template_directory'); ?>/img/check_trener.png" alt=""> <p class="pull-left small-m-left xs-m-top text-bold">Wybrano trenera</p> </div> </div> <div class="col-sm-6"> <a href="szczegoly-trenera" target="_blank"><h3 class="btn-custom_bg pull-right">Zobacz profil trenera</h3></a> </div> </section> <figure id="trener_3"> <img class="img-responsive center" src="<?php bloginfo('template_directory'); ?>/img/ex_wybierz_trenera1.jpg" alt=""> <figcaption> <h4>Kasia Kowalska</h4> </figcaption> <a> <div class="click_to text-center"> <i class="fa fa-plus"></i> <p>Kliknij aby wybrać trenera</p> </div> </a> </figure> <section class="row"> <div class="col-sm-6 xs-p-top"> <div class="choose_info trener_3" style="display:none;"> <img class="pull-left" src="<?php bloginfo('template_directory'); ?>/img/check_trener.png" alt=""> <p class="pull-left small-m-left xs-m-top text-bold">Wybrano trenera</p> </div> </div> <div class="col-sm-6"> <a href="szczegoly-trenera" target="_blank"><h3 class="btn-custom_bg pull-right">Zobacz profil trenera</h3></a> </div> </section> 

Why not assign the class trener_3 to the div.row element? 为什么不将class trener_3分配给div.row元素?

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

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