gpt4 book ai didi

asp.net - 在 ASP.NET RadioButtonList ListItem 上设置 CSS 类

转载 作者:技术小花猫 更新时间:2023-10-29 10:10:22 25 4
gpt4 key购买 nike

有没有办法在单选按钮列表中的输入项上设置 CSS 类?我想在 jQuery 中按类引用这些表单值。

给定一个在 ListItems 上设置类的 ASP.NET RadioButtonList:

 <asp:RadioButtonList ID="RadioButtonList" runat="server">
<asp:ListItem class="myClass" Text="Yes" Value="1" />
<asp:ListItem class="myClass" Text="No" Value="0" />
</asp:RadioButtonList>

将呈现为:

 <span id="RadioButtonList" class="radioButtonListField myClass">
<span class="myClass">
<input id="RadioButtonList_0" type="radio" value="1"
name="RadioButtonList"/>
<label for="RadioButtonList_0">Yes</label>
</span>
<span class="myClass">
<input id="RadioButtonList_1" type="radio" value="0"
name="RadioButtonList"/>
<label for="RadioButtonList_1">No</label>
</span>
</span>

不幸的是,“myClass”类被添加到 <span>包含单选按钮项,而不是 <input>本身。我怎样才能让它看起来像这样:

 <span id="RadioButtonList" class="radioButtonListField myClass">
<span>
<input id="RadioButtonList_0" class="myClass" type="radio" value="1"
name="RadioButtonList"/>
<label for="RadioButtonList_0">Yes</label>
</span>
<span>
<input id="RadioButtonList_1" class="myClass" type="radio" value="0"
name="RadioButtonList"/>
<label for="RadioButtonList_1">No</label>
</span>
</span>

(这甚至没有涉及将类添加到动态绑定(bind)的 RadioButtonList 的问题。)

最佳答案

是的,RadioButtonList 呈现出可怕的 HTML。

无论如何,从 jQuery 中获取它们仍然很容易。

尝试

$('span.myclass input:radio')

上面将获取类为“myclass”的跨度内的所有单选按钮。

关于asp.net - 在 ASP.NET RadioButtonList ListItem 上设置 CSS 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1070960/

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