Как обработать изменение параметра списка радиокнопок с помощью jQuery - PullRequest
3 голосов
/ 07 декабря 2011

У меня на странице есть элемент управления RadioButtonList с несколькими вариантами. Я хочу обработать изменение его параметров и, в соответствии со значением выбранного параметра, выполнить работу.

Это не работает:

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

Как я могу справиться с этим?

спасибо

Ответы [ 3 ]

17 голосов
/ 07 декабря 2011

Вам просто нужно связать сами входы, а не их группу:

$(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());
    });
});
1 голос
/ 29 апреля 2016

Может быть, это поможет вам:)

$('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();
             }

        });
0 голосов
/ 27 июля 2016
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>
...