【问题标题】:Add CssClass to asp:ListItem within CheckBoxList将 CssClass 添加到 asp:ListItem 中 CheckBoxList
【发布时间】:2014-08-01 13:02:10
【问题描述】:

我想在<asp:CheckBoxList> 内向<asp:ListItem> 添加一个Css-Class。

这是我的代码:

<fieldset class="group">
    <asp:CheckBoxList ID="checkboxID" runat="server" CellPadding="5" CellSpacing="5" RepeatColumns="1" CssClass="choose" RepeatDirection="Vertical" RepeatLayout="UnorderedList" TextAlign="Right" EnableViewState="true">
        <asp:ListItem Text="Checkbox 1" Value="checkbox_10" />
    </asp:CheckBoxList>
</fieldset>

这是我得到的:

<fieldset class="group">
    <ul id="checkboxID2" class="choose">
        <li>
            <input id="checkboxID_0" type="checkbox" name="checkboxID$0" value="checkbox_10" />
            <label for="checkboxID_0">Checkbox 1</label>
        </li>
    </ul>
</fieldset>

但我需要一个 css 类作为输入字段:

<fieldset class="group">
    <ul id="checkboxID2" class="choose">
        <li>
            <input id="checkboxID_0" type="checkbox" name="checkboxID$0" value="checkbox_10" class="replace" />
            <label for="checkboxID_0">Checkbox 1</label>
        </li>
    </ul>
</fieldset>

我发现了这两个问题:
Is there a possibility to assign CssClass to CheckBox within CheckBoxList
Applying Styles To ListItems in CheckBoxList

但我的问题是:
有没有办法在没有编程方式的情况下添加 css 类?
我试过&lt;asp:ListItem class="replace"&gt;,但这会在输入字段周围生成&lt;span class="replace"&gt;,但不起作用。此外,我无法更改 css 类。

【问题讨论】:

    标签: css asp.net checkboxlist


    【解决方案1】:

    您可以通过两种方式做到这一点: jQuery >

    $("#selectboxid option:eq(0)").css("color","red");// you can set any color
    

    或 Javascript >

    checkbox {
        color:red
    }
    

    【讨论】:

    • 是否可以这样设置一个完整的css类而不是一个属性(颜色)?
    • 是的,$("#selectboxid option:eq(0)").css("class","classname");
    • 我不能接受这个作为答案,因为它并不完全正确。但是您会因提供帮助而获得支持!
    • 是的@Thomas,我现在意识到了,因为我认为我误读了你的问题,而不是复选框我假设它的下拉列表
    【解决方案2】:

    TechGirl 的建议下,我想出了这个:

    <script>
        $("input[type='checkbox']").addClass("replace");
    </script>
    

    【讨论】:

      【解决方案3】:

      将其添加到

      <style>
      input[type=checkbox] {
                  width: 100px;
              }
      </style>
      

      希望能成功

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-10
        • 2023-03-23
        • 1970-01-01
        • 2015-06-19
        • 1970-01-01
        相关资源
        最近更新 更多