how can i get the value of radiobox in jquery

This question already has an answer here:

  • How can I know which radio button is selected via jQuery? 29 answers

  • 你应该得到按下复选框的值

    var religion = $("input[name=religion]:checked").val();
    alert(religion)
    

    const radio1Value = document.querySelector("input").value;
    console.log(radio1Value);
    <input type="radio" name="religion" class="chk" name="religion" value="muslim">Muslim
    <input type="radio" name="religion" class="chk" name="religion" value="christian">Christian
    <input type="radio" name="religion" class="chk" name="religion" value="hindu">Hindu

    try this

    $(document).ready(function(){
            $("input[type='button']").click(function(){
                var radioValue = $("input[name='religion']:checked").val();
                if(radioValue){
                    alert("Your are a - " + radioValue);
                }
            });
    
        });
    

    Demo

    链接地址: http://www.djcxy.com/p/24590.html

    上一篇: jQuery获取所选单选按钮的值

    下一篇: 我如何得到jquery中radiobox的价值