【问题标题】:Get the Checkboxlist value when unchecked Client-Side未选中 Client-Side 时获取 Checkboxlist 值
【发布时间】:2015-10-29 18:54:45
【问题描述】:

未选中项目时如何获取Checkboxlist值的值?我尝试了以下代码,但没有得到值。请告诉我。

JQuery
----------------

    $(document).ready(function () {
        $("#<%=chkboxTypeList.ClientID%> input[type=checkbox]").click(function () {

            if (!this.checked) {
               alert($(this).val());
            }

        });

.aspx
-------------------
                        <asp:CheckBoxList ID="chkboxTypeList" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Text="TEST 1" Value="1"></asp:ListItem>
                            <asp:ListItem Text="TEST 2" Value="2"></asp:ListItem>
                            <asp:ListItem Text="TEST 3" Value="3"></asp:ListItem>
                        </asp:CheckBoxList>

【问题讨论】:

    标签: jquery asp.net


    【解决方案1】:

    checkboxlist 的值存储在Viewstate 中,而不是在客户端呈现。

    获得价值客户端的一种方法是使用Attribute

    <asp:CheckBoxList ID="chkboxTypeList" runat="server" RepeatDirection="Horizontal">
         <asp:ListItem Text="TEST 1" Value="1" ClientValue="1"></asp:ListItem>
         <asp:ListItem Text="TEST 2" Value="2" ClientValue="2"></asp:ListItem>
         <asp:ListItem Text="TEST 3" Value="3" ClientValue="3"></asp:ListItem>
    </asp:CheckBoxList>
    

    然后呈现如下:-

    <td>
      <span clientvalue="2">
        <input id="chklstStates_1" type="checkbox" name="chklstStates$1">
        <label for="chklstStates_1">TEST 2</label>
      </span>
    </td>
    

    然后使用:-

    $(document).ready(function () {
    
        $("#<%=chkboxTypeList.ClientID%> input[type=checkbox]").change(function () {
    
            var value = $(this).parent().attr('clientvalue');
    
            if (!this.checked) {
               alert(value);
            }
    
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2015-02-10
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 2014-06-24
      相关资源
      最近更新 更多