2

Web アプリケーションの 1 つにチェックボックス リスト コントロールがあります。SelectedIndexChanged イベントを処理するために JavaScript を使用したいと考えています。

チェックボックスリストは次のようになります

<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 に答える