我有这个代码制作一个按钮并从服务器获取一些价值。
然后在加载(初始化视图)时我得到值 = 1,我需要自动打开切换开关。
代码如下
var value = 1;Run Code Online (Sandbox Code Playgroud)
.switch {
position: relative;
display: inline-block;
width: 100px;
height: 34px;
}
.switch input {
display: none;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ca2222;
-webkit-transition: .4s;
transition: .4s;
}
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked+.slider { …Run Code Online (Sandbox Code Playgroud)