我需要使该切换效果在任何单个复选框上工作。例如,我会检查第二个(样式)复选框,它会自动切换,其他所有人都不会受到影响。 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 –
好得多。我收回了我的近距离投票。 –