我需要使該切換效果在任何單個複選框上工作。例如,我會檢查第二個(樣式)複選框,它會自動切換,其他所有人都不會受到影響。 Thx非常需要幫助。CSS:複選框切換效果僅適用於第一個複選框
https://jsfiddle.net/99asehku/
HTML:
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div><br><br>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div><br><br>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch1" class="onoffswitch-checkbox1" id="myonoffswitch1" checked>
<label class="onoffswitch-label1" for="myonoffswitch1">
<span class="onoffswitch-inner1"></span>
<span class="onoffswitch-switch1"></span>
</label>
</div>
CSS:
所有ID的.onoffswitch {
position: relative; width: 58px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 10px; padding: 0; line-height: 10px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ANO";
padding-left: 10px;
background-color: #34A7C1; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "NE";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 10px; margin: 0px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 44px;
border: 2px solid #999999; border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
我已經自由地評論了你的JSFiddle鏈接,因爲你故意繞過堆棧溢出的*** JSFiddle鏈接必須伴隨代碼***警告通過將鏈接放置在代碼塊中。我還投票決定關閉這個問題,因爲你在問題本身沒有提供任何代碼。 –
對不起,我沒有爲自己翻譯這個錯誤信息,我迫切需要得到解決這個問題的任何提示。我很高興看到消除這種負面聲譽。 Thx –
好得多。我收回了我的近距離投票。 –