我正在尝试在我的项目中创建一个切换按钮,当我添加一个服务器控件复选框时,无法选中复选框,但是当我使用html控件并且可以选中该复选框时,我缺少什么
<div class="material-switch ">
<asp:CheckBox ID="CheckBox1" runat="server" />
<label for="CheckBox1" class="label-primary" ></label>
</div>
使用Css
.material-switch > input[type="checkbox"] {
display: none;
}
.material-switch > label {
cursor: pointer;
height: 0px;
position: relative;
width: 40px;
}
.material-switch > label::before {
background: rgb(0, 0, 0);
box-shadow: inset 0px 0px 10px rgba(0, 0, 0, 0.5);
border-radius: 8px;
content: '';
height: 16px;
margin-top: -8px;
position:absolute;
opacity: 0.3;
transition: all 0.4s ease-in-out;
width: 40px;
}
.material-switch > label::after {
background: rgb(255, 255, 255);
border-radius: 16px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
content: '';
height: 24px;
left: -4px;
margin-top: -8px;
position: absolute;
top: -4px;
transition: all 0.3s ease-in-out;
width: 24px;
}
.material-switch > input[type="checkbox"]:checked + label::before {
background: inherit;
opacity: 0.5;
}
.material-switch > input[type="checkbox"]:checked + label::after {
background: inherit;
left: 20px;
}
答案 0 :(得分:0)
将属性的标签从“someSwitchOptionPrimary”更改为asp:CheckBox的id。工作实例如下:
<div class="material-switch">
<asp:CheckBox ID="CheckBox1" runat="server" />
<label for="CheckBox1" class="label-primary" ></label>
</div>
答案 1 :(得分:0)
确定。我知道了 !!!!!!!
我收到了这个问题,因为当控件呈现给网页时,复选框的ID发生了变化......它附加了ctl00_RightPlaceHolder_,因为标签控件无法找到控件,因为它正在查找具有此id的控件&#34; CheckBox1&#34;
所以我添加ClientIDMode="Static"
以使ID静态
感谢!!!!