格式化复选框?

Lia*_*iam 2 .net css c# asp.net checkbox

我正在使用.net构建的网站上工作,即时尝试输出我的标记......

<span class="check-input">
     <!-- Terms -->
     <input type="checkbox" id="terms" class="terms checkbox">
     <label for="terms">I agree to the terms and conditions</label>
     <input type="checkbox" id="age" class="age checkbox">
     <label for="age">I am over 18 years old</label>
     </span>
Run Code Online (Sandbox Code Playgroud)

只有我的开发人员实施的代码才是......

<!-- Terms -->
       <asp:CheckBox ID="CB_Agree" 
       Text="I agree to the terms and conditions" runat="server" TabIndex="4" />

       <asp:CheckBox ID="CB_Age" 
       Text="I am over 18 years old" runat="server" TabIndex="5" />
Run Code Online (Sandbox Code Playgroud)

这是输出我的数据...

<span class="check-input">
<!-- Terms -->
<span class="terms checkbox">
    <input type="checkbox" tabindex="4" name="ctl00$ContentPlaceHolder1$CB_Agree" id="ctl00_ContentPlaceHolder1_CB_Agree">
    <label for="ctl00_ContentPlaceHolder1_CB_Agree">I agree to the terms and conditions</label>
</span>
<span class="age checkbox">
    <input type="checkbox" tabindex="5" name="ctl00$ContentPlaceHolder1$CB_Age" id="ctl00_ContentPlaceHolder1_CB_Age">
    <label for="ctl00_ContentPlaceHolder1_CB_Age">I am over 18 years old</label>
</span>
</span>
Run Code Online (Sandbox Code Playgroud)

Tim*_*ter 5

然后您(或您的开发人员)需要将该CssClass属性添加到复选框.

例如:

<asp:CheckBox ID="CB_Agree" 
       CssClass="terms checkbox"
       Text="I agree to the terms and conditions" runat="server" TabIndex="4" />
Run Code Online (Sandbox Code Playgroud)

它还有一个InputAttributes控制复选框的布局和LabelAttributes跨度的属性.

因此,您可以通过以下方式在代码隐藏中应用不同的背景颜色:

CB_Agree.InputAttributes.CssStyle.Add("background-color", "Red");
CB_Agree.LabelAttributes.CssStyle.Add("background-color", "Green");
Run Code Online (Sandbox Code Playgroud)