我toggleClass功能僅適用於只是一次 - 旋轉和我說,如果else條件我的jQuery代碼得到的類名toggleClass工程,我知道那一定是作品永遠只有一次
我的HTML結構;
<div class="form-elements">
<input type="button" name="d5" class="d5" />
<input type="button" name="d4" class="d4" />
<input type="button" name="d3" class="d3" />
<input type="button" name="d2" class="d2" />
<input type="button" name="d1" class="d1" />
</div>
CSS文件
.d1 {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d1.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px; padding: 0;
margin: 0;
}
.d1_pasif {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d1_pasif.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px; padding: 0;
margin: 0;
}
.d2 {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d2.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px; padding: 0;
margin: 0;
}
.d2_pasif { background: url(https://anitur.streamprovider.net/images/otel-filtre/d2_pasif.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px; padding: 0;
margin: 0;
}
.d3 {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d3.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px; padding: 0;
margin: 0;
}
.d3_pasif {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d3_pasif.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px; padding: 0;
margin: 0;
}
.d4 {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d4.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px; padding: 0;
margin: 0;
}
.d4_pasif {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d4_pasif.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px;
}
.d5 {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d5.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px;
}
.d5_pasif {
background: url(https://anitur.streamprovider.net/images/otel-filtre/d5_pasif.png);
border: 0;
display: inline-block;
height: 32px;
width: 32px;
}
,這是我的js文件
$(".form-elements input[type='button']").on("click", function() {
var el = $(this).attr("class");
if($(this).hasClass("d1")){
$(".d1").toggleClass('d1 d1_pasif');
}else if($(this).hasClass("d2")){
$(".d2").toggleClass('d2 d2_pasif');
}else if($(this).hasClass("d3")){
$(".d3").toggleClass('d3 d3_pasif');
}else if($(this).hasClass("d4")){
$(".d4").toggleClass('d4 d4_pasif');
}
else if($(this).hasClass("d5")){
$(".d5").toggleClass('d5 d5_pasif');
}
return false;
});
它的工作非常好,但也有一些是我的理解,這是不行的我的網頁,但在演示頁的作品完美 [我的演示鏈接](http://www.anitur.com.tr/deneme-otel-liste) –