我如何得到jquery中radiobox的价值

这个问题在这里已经有了答案:

  • 我如何知道通过jQuery选择了哪个单选按钮? 29个答案

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

    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

    尝试这个

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

    演示

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

    上一篇: how can i get the value of radiobox in jquery

    下一篇: How can i know which radio input is selected in jQuery?