gpt4 book ai didi

c# - 格式化复选框?

转载 作者:行者123 更新时间:2023-12-03 05:04:05 24 4
gpt4 key购买 nike

我正在开发一个使用 .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>

只有我的开发人员编写的代码是...

<!-- 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" />

这将我的数据输出为...

<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>

最佳答案

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

例如:

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

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

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

CB_Agree.InputAttributes.CssStyle.Add("background-color", "Red");
CB_Agree.LabelAttributes.CssStyle.Add("background-color", "Green");

关于c# - 格式化复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10585324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com