【问题标题】:Getting SelectedIndexChanged event of checkboxlist using javascript使用javascript获取复选框列表的SelectedIndexChanged事件
【发布时间】:2012-03-20 03:40:26
【问题描述】:

我在其中一个 Web 应用程序中有一个复选框列表控件。我想使用 javascript 来处理 SelectedIndexChanged 事件。

复选框列表是这样的

<asp:CheckBoxList ID="CheckBoxList1" runat="server">
    <asp:ListItem>One</asp:ListItem>
    <asp:ListItem>Two</asp:ListItem>
    <asp:ListItem>Three</asp:ListItem>
    <asp:ListItem>Four</asp:ListItem>
    <asp:ListItem>Five</asp:ListItem>
</asp:CheckBoxList> 

如何使用 javascript 获取 SelectedIndexChanged 事件?

【问题讨论】:

    标签: javascript selectedindexchanged


    【解决方案1】:

    在服务器端..放下面的..

    CheckBoxList1.Attributes.Add("onclick", "ChangeCheckBox();");
    

    在客户端 JavaScript 部分,实现以下函数

    function ChangeCheckBox() {}
    

    【讨论】:

    • 是的,我可以通过这个获得复选框列表事件。我的 UI 中还有一个复选框,所以我使用相同的 onclick 来获取复选框事件。 But I am not getting this event when checkbox is selected.我们应该为复选框使用不同的事件吗?
    【解决方案2】:

    你可以使用下面的代码

      document.getElementById('CheckBoxList1').onchange = function () {
                    var input = document.getElementById('CheckBoxList1').getElementsByTagName("input")
                    for (var i = 0; i < input.length; i++) {
                        if (input[i].type == "checkbox") {
                            if (input[i].checked == true) {
                                alert(input[i].value);//Get all the checked checkboxes
                            }
                        }
                    }
                }
    

    【讨论】:

      猜你喜欢
      • 2014-05-10
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      • 2018-06-17
      • 2010-11-20
      • 1970-01-01
      • 2013-03-29
      • 1970-01-01
      相关资源
      最近更新 更多