如何使用jQuery处理单选按钮列表选项的更改

How to Handle Radio Button List Option change with jQuery

本文关键字:选项 列表 单选按钮 何使用 jQuery 处理      更新时间:2023-09-26

我的页面上有一个有多个选项的RadioButtonList控件。我想处理它的选项的变化,并根据所选选项的值,做工作。

这行不通:

 $(document).ready(function () {
        $('#RadioButtonList1').change(function () {
            if ($(this).is(':checked')) {
                alert("yes");
            }
        });
    });

我该如何处理?

谢谢

您只需要绑定输入本身,而不是它们的组:

$(document).ready(function () {
    $('#RadioButtonList1 input').change(function () {
        // The one that fires the event is always the
        // checked one; you don't need to test for this
        alert($(this).val());
    });
});

也许这条对你有帮助:)

$('form#package_information_id').on('change','.shipment_type_radio_class',function(){
             var currentselval = $(this).find('input[type="radio"]:checked');
             //console.log(currentselval);
             if(currentselval.val()=='dropoff') 
             {
                $('.pickup_detail_class').hide();
             }else
             {
                $('.pickup_detail_class').show();
             }
        });
enter code here
<div>
    <asp:RadioButtonList ID="rblTest" runat="server">
        <asp:ListItem>10</asp:ListItem>
        <asp:ListItem>20</asp:ListItem>
        <asp:ListItem>30</asp:ListItem>
        <asp:ListItem>40</asp:ListItem>``
    </asp:RadioButtonList>
</div>
  <script type="text/javascript">
    $(function() {
            var val = "";
            val = $('[id*=rblTest]').find('input:checked').val();
            if (val != "" && val != undefined) {
                alert("Selected item value is : " + val)
            }
        });

</script>