繁体   English   中英

单击关闭下拉框

[英]Dropdown box close on click

我有一个DIV,它会在单击时扩展,当前在单击另一个DIV时会关闭,但我也希望在单击时关闭,我的代码如下:

jQuery:

$(function(){
  $('.opReview').click(function(){
    $('.review').addClass('hide');
    $(this).children('.review').toggleClass('hide');
  });
});

HTML标记(可以忽略Wordpress代码)

<article class="sixteen columns opReview">          

 <img class="opLogo" src="<?php bloginfo('stylesheet_directory'); ?>/img/core/operator/90x58_operatorlogo/<?php echo $op_logo?>.png" alt="<?php echo($op_title)?>" >

  <div class="list_details">
    <div class="reviewTitle"><p>Click To </br> Read a review</p> </div>
  </div>

  <button class="claimBtn"><i class="fa fa-chevron-circle-right fa-rotate-90"></i></button> 
        <div class="clear"></div>

  <div class="review hide">
          <h1><?php echo $op_name; ?></h1>
            <p><?php echo $operator_review; ?></p>
        </div>
</article>

这段代码将隐藏所有.review元素,然后切换活动元素,将其取消隐藏

$('.review').addClass('hide');
$(this).children('.review').toggleClass('hide');

您需要从第一个选择器中排除当前项目

$(this).siblings('.review').addClass('hide');
$(this).children('.review').toggleClass('hide');

暂无
暂无

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

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