坐落在一个ASP.NET单选按钮列表的ListItem CSS类 [英] Set a CSS class on an ASP.NET RadioButtonList ListItem

查看:126
本文介绍了坐落在一个ASP.NET单选按钮列表的ListItem CSS类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法来设置在一个单选按钮列表中的输入项CSS类?我想用类jQuery中引用这些形式的值。

Is there any way to set a CSS class on an input item in a radio button list? I'd like to reference these form values by class in jQuery.

给定一个ASP.NET单选按钮列表上的ListItems的设置类:

Given an ASP.NET RadioButtonList with classes set on the ListItems:

 <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的级被添加到&所述;跨度&GT; 包含的单选按钮项,而不是&所述;输入&GT; 本身。我怎么能得到它看起来像这个:

Unfortunately, the "myClass" class is added to the <span> that contains the radio button item, not the <input> itself. How could I get it to look like this instead:

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

(这还不进入添加类来动态绑定RadioButtonLists的问题。)

(This does not even get into the issue of adding the classes to dynamically bound RadioButtonLists.)

推荐答案

是,RadioButtonList的渲染恐怖的HTML。

Yes, RadioButtonList renders horrible HTML.

不管怎样,它仍然容易从jQuery的得到它们。

Anyway, it's still easy to get them from jQuery.

尝试

$('span.myclass input:radio')

以上将获得与类MyClass的跨度内的所有单选按钮。

Above will get all the radio buttons inside the span with class 'myclass'.

这篇关于坐落在一个ASP.NET单选按钮列表的ListItem CSS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆