asp.Net   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在ASP.NET RadioButtonList ListItem上设置CSS类大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法在单选按钮列表中的输入项上设置CSS类?我想在jQuery中通过类来引用这些表单值。

给定一个ASP.NET RadioButtonList与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”类会添加到< 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>

(这甚至不涉及将类添加到动态绑定的RadioButtonLists的问题。)

解决方法

是的,RadioButtonList呈现可怕的HTML。

无论如何,它仍然很容易让他们从jQuery。

尝试

$('span.myclass input:radio')

上面将获得跨’myclass’类中的所有单选按钮。

大佬总结

以上是大佬教程为你收集整理的在ASP.NET RadioButtonList ListItem上设置CSS类全部内容,希望文章能够帮你解决在ASP.NET RadioButtonList ListItem上设置CSS类所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: