gpt4 book ai didi

javascript - 如何取消突出显示不活动的 block

转载 作者:太空宇宙 更新时间:2023-11-04 02:05:55 24 4
gpt4 key购买 nike

伙伴们,我有以下代码。如果我单击一个表,它会突出显示,然后如果我单击另一个,前一个仍然亮着,我按下的下一个也是如此。我该如何编辑它,以便在我单击另一个表格时,前一个表格不突出显示?

$('.pricing-customer').on('click', function(){
$(this).toggleClass('active');
$(this).children().toggleClass('active');
});
.pricing-customer {
background: #fff;
min-height: 250px;
cursor: pointer;
transition: all .3s ease-in-out;
margin-bottom: 20px;
padding: 10px 0px 25px 0px;
}
p.pricing-number {
font-size: 52px;
margin-bottom: 10px;
margin-top: 20px;
color: #fead0d;
}
p.pricing-monthes {
color: #5e6977;
font-size: 14px;
line-height: 21px;
padding-bottom: 20px;
border-bottom: 1px solid #e1e8ee;
}
p.emails {
color: #444;
font-size: 16px;
line-height: 21px;
}
.pricing-customer:hover, .pricing-customer.active {

background-color: #333;
}
.pricing-customer:hover p , .pricing-customer p.active{
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pricing-customer col-sm-12 col-sm-3 text-center">
<h3><?php echo $t_title; ?></h3>
<p class="pricing-number">$ 70</p>
<br>
<p class="pricing-monthes">per week/month</p>
<p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
<h3><?php echo $t_title; ?></h3>
<p class="pricing-number">$ 70</p>
<br>
<p class="pricing-monthes">per week/month</p>
<p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
<h3><?php echo $t_title; ?></h3>
<p class="pricing-number">$ 70</p>
<br>
<p class="pricing-monthes">per week/month</p>
<p class="pricing-emails">100 000 emails</p>
</div>

最佳答案

使用 siblings而不是 child 。我希望这就是您要找的。

$('.pricing-customer').on('click', function(){
$(this).toggleClass('active');
$(this).siblings().removeClass('active');
});
.pricing-customer {
background: #fff;
min-height: 250px;
cursor: pointer;
transition: all .3s ease-in-out;
margin-bottom: 20px;
padding: 10px 0px 25px 0px;
}
p.pricing-number {
font-size: 52px;
margin-bottom: 10px;
margin-top: 20px;
color: #fead0d;
}
p.pricing-monthes {
color: #5e6977;
font-size: 14px;
line-height: 21px;
padding-bottom: 20px;
border-bottom: 1px solid #e1e8ee;
}
p.emails {
color: #444;
font-size: 16px;
line-height: 21px;
}
.pricing-customer:hover, .pricing-customer.active {

background-color: #333;
}
.pricing-customer:hover p , .pricing-customer.active p{
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pricing-customer col-sm-12 col-sm-3 text-center">
<h3><?php echo $t_title; ?></h3>
<p class="pricing-number">$ 70</p>
<br>
<p class="pricing-monthes">per week/month</p>
<p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
<h3><?php echo $t_title; ?></h3>
<p class="pricing-number">$ 70</p>
<br>
<p class="pricing-monthes">per week/month</p>
<p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
<h3><?php echo $t_title; ?></h3>
<p class="pricing-number">$ 70</p>
<br>
<p class="pricing-monthes">per week/month</p>
<p class="pricing-emails">100 000 emails</p>
</div>

关于javascript - 如何取消突出显示不活动的 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40755343/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com