2

我在其中一个 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 事件?

4

2 回答 2

4

在服务器端..放以下内容..

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

在客户端 JavaScript 部分,实现以下功能

function ChangeCheckBox() {}
于 2012-03-20T03:49:07.337 回答
0

你可以使用下面的代码

  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
                        }
                    }
                }
            }
于 2012-03-20T04:03:53.007 回答