gpt4 book ai didi

javascript - removeClass 和 removeClass 图像不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 01:50:53 25 4
gpt4 key购买 nike

siblings('.xx')有没有错误?单击时不想重复图像抱歉,我的英语太差了:(

$(document).ready(function() {
//$(".ok").removeClass("imga");
//$('.ok2').removeClass('imga').siblings('.ok2').addClass("imga");
$('.item').click(function() {
var id = $(this).attr('id');
var xx = "ok" + id;
$('.ok' + id).removeClass('imga').siblings('.xx').addClass("imga");
$(this).addClass('active').siblings().removeClass('active');
});
});
.active {
font-weight: 900;
color: blue;
}

.hover {
color: blue;
}

.imga {
-webkit-filter: grayscale(1);
filter: grayscale(1);
margin: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="item" id="1">
<img class="ok1 imga" src="http://icons.iconarchive.com/icons/ampeross/qetto/128/icon-developer-icon.png"><br>
image 1
</div>
<div class="item" id="2" width="50" width="50">
<img class="ok2 imga" src="http://icons.iconarchive.com/icons/ampeross/qetto/128/icon-developer-icon.png"><br>
image 2
</div>
<div class="item" id="3" width="50" width="50">
<img class="ok3 imga" src="http://icons.iconarchive.com/icons/ampeross/qetto/128/icon-developer-icon.png"><br>
image 3
</div>

最佳答案

为什么不使用 active 类来改变图像显示呢?

$('.item').click(function(){  
$(this).addClass('active').siblings().removeClass('active');
});
.active{
font-weight:900;
color:blue;
}

.item:not(.active) img {
-webkit-filter: grayscale(1);
filter: grayscale(1);
margin:auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="item" id="1"><img class="ok1 imga" src="http://icons.iconarchive.com/icons/ampeross/qetto/128/icon-developer-icon.png"><br>image 1</div>
<div class="item" id="2" width="50" width="50"><img class="ok2 imga" src="http://icons.iconarchive.com/icons/ampeross/qetto/128/icon-developer-icon.png"><br>image 2</div>
<div class="item" id="3" width="50" width="50"><img class="ok3 imga" src="http://icons.iconarchive.com/icons/ampeross/qetto/128/icon-developer-icon.png"><br>image 3</div>

关于javascript - removeClass 和 removeClass 图像不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43513167/

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