jQuery get value of selected radio button

前端 未结 27 1559
耶瑟儿~
耶瑟儿~ 2020-11-22 13:55

The problem statement is simple. I need to see if user has selected a radio button from a radio group. Every radio button in the group share same id.

The problem is

27条回答
  •  北海茫月
    2020-11-22 14:29

    The best way to explain this simple topic is by giving simple example and reference link:-

    In the following example we have two radio buttons. If the user selects any radio button, we will display the selected radio button value in a alert box.

    Html:

    Male
    Female
    others

    jquery:-

     $(document).ready(function(){
            $('#Demo input').on('change', function() {
                alert($('input[name="Gender"]:checked', '#Demo').val());
            });
        });
    

提交回复
热议问题