jQuery get value of selected radio button

前端 未结 27 1567
耶瑟儿~
耶瑟儿~ 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:36

    1. In your code, jQuery just looks for the first instance of an input with name q12_3, which in this case has a value of 1. You want an input with name q12_3 that is :checked.
    $(function(){
        $("#submit").click(function() {     
            alert($("input[name=q12_3]:checked").val());
        });
    });
    
    1. Note that the above code is not the same as using .is(":checked"). jQuery's is() function returns a boolean (true or false) and not an element.

提交回复
热议问题