开关箱:多个开关箱不工作在我的页面
Switch box:multiple switch boxes are not working in my page
我有一个开关按钮工作良好。但是当我使用更多的开关按钮时,功能就不起作用了。如果我点击第二个,第一个开关就会从开变成关或者从关变成开
这是我的css和Html:
<html>
<head>
<style type="text/css">
.onoffswitch {
position: relative; width: 90px;
-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 #E6E6E6; border-radius: 50px;
}
.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: 36px; padding: 0; line-height: 36px;
font-size: 16px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "YES";
padding-left: 13px;
background-color: #61A1E1; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "NO";
padding-right: 13px;
background-color: #F01F1F; color: #FFFFFF;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 27px; margin: 4.5px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 50px;
border: 2px solid #E6E6E6; border-radius: 50px;
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;
}
</style>
</head>
<body>
<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>
<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>
</body>
</html>
现在我想让它分别为开关按钮工作。我不明白我错在哪里。
请帮我一下。
提前致谢
working jsfiddle demo
在演示中,当我点击第二个开关按钮时,第一个按钮正在移动
两个元素需要有不同的id才能正常工作。请参阅更新后的提琴https://jsfiddle.net/mileandra/SkRN9/30/
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked="checked" />
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch2" checked="checked" />
<label class="onoffswitch-label" for="myonoffswitch2">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
相关文章:
- 为什么我的开关按钮不起作用
- 我的开关结构似乎有效(JavaScript 控制结构)
- 中断不适用于我的开关语句
- 为什么我的引导开关在使用 foreach 构建的淘汰表中不起作用
- 我的开关语句或文档.write();不起作用,我无法修复它
- 带返回和断开的开关箱
- 在开关箱里放一个开关箱是不是不好的做法
- 如何检测开关箱的空输入值
- “0”的执行顺序是什么;开关箱”;在节点js中
- 为什么这个开关不能和我的onchange一起工作
- 如何开始我的jquery隐藏开关
- 我在哪里添加可见性开关在我的JavaScript
- JS循环不循环,直到我注释掉我的开关方法
- 选择带开关箱的选项计算
- Javascript's开关之谜在我的代码
- 为什么不'我的php代码是否使用复选框信息来迭代我的开关
- 开关箱:多个开关箱不工作在我的页面
- 用更好的东西替换开关箱
- 简单的开关箱不工作
- 我想让我的项目网站的#菜单按钮像开关一样工作