如何在javascript中获取asp清单框的价值?

时间:2014-07-28 05:37:52

标签: javascript asp.net .net

嗨我正在使用此代码获取值,但它只显示文本而不是值,请帮助我... 我的复选框列表是:

  <asp:CheckBoxList  ID="CheckBoxList1" runat="server" onchange=" GetSelectedItem();">
                     <asp:ListItem  Text ="Show only Refundable  Fares"  Value ="false"  ></asp:ListItem>
                     <asp:ListItem Text ="helloe" Value ="true" ></asp:ListItem>
                     <asp:ListItem Text ="" Value ="" ></asp:ListItem>
                    </asp:CheckBoxList>

我的javascript代码是:

<script type = "text/javascript">
    function GetSelectedItem() {

        var CHK = document.getElementById("<%=CheckBoxList1.ClientID%>");
      //  var CHK = document.getElementById("CheckBoxList1").;

        var checkbox = CHK.getElementsByTagName("input");
       var label = CHK.getElementsByTagName("label");
       var refund = new Array();
       var values = "";
        for (var i = 0; i < checkbox.length; i++) {
            if (checkbox[i].checked) {

            refund[i] = label[i].innerText;

             alert("Selected = " + refund);

            }
        }
        $('#hdnrefund').val(refund);
        return false;
    }
</script>

1 个答案:

答案 0 :(得分:0)

更改

label[i].innerText;

label[i].value;