javascript jquery 获取单选按钮值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19310918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 15:07:09  来源:igfitidea点击:

jquery get radio button value

javascriptphpjquery

提问by Crays

all i want is to use the .get function to retrieve the selected/checked radio button value, i think i got the code right, but the sequence is kinda wrong

我想要的只是使用 .get 函数来检索选定/选中的单选按钮值,我想我的代码是正确的,但序列有点错误

$.get('burgerorder_check.php', function(data) {
                inputVal = $('input[type=radio][name=timeslot]:checked').val();
            });

then after i get the inputVal, i want to reload a particular div with that specific input

然后在我获得 inputVal 后,我想用该特定输入重新加载特定的 div

    setInterval(getData,1000);
    getData();
    function getData(){
    if( inputField ) {
    $("#timeslot").load('burgerorder_check.php?dateselect='+inputField+'&inputselect=a'+inputVal);
    };

any help? So far the inputVal value is null :(

有什么帮助吗?到目前为止 inputVal 值为 null :(

Full block of code :

完整的代码块:

$(document).ready(function(){
        var inputField;
        var inputVal;


        $("#dateslot").change(function(){
        inputField = $('#dateslot').val();
        });

        $.get('burgerorder_check.php', function(data) {
            inputVal = $('input[type=radio][name=timeslot]:checked').val();
        });

        setInterval(getData,1000);
        getData();
        function getData(){
        if( inputField ) {
        $("#timeslot").load('burgerorder_check.php?dateselect='+inputField+'&inputselect=a'+inputVal);
        };
        };


});

回答by Nandakumar

$('input[name='radio_button_name']:checked').val() 

回答by Babbitt

Try this

试试这个

I hope to be able to help you

我希望能帮到你

Jquery Code:
$("#ssss").bind("change",function(value){
    var test = $(this).children(":checked").val();
    alert(test)
})

HTML Code:
<div ng-app="App" id="ssss">
   <input type="radio" name='test'  value="red">  Red <br/>
   <input type="radio" name='test' value="green"> Green <br/>
   <input type="radio" name='test' value="blue"> Blue <br/>
</div>

http://jsfiddle.net/5qbG6/6/

http://jsfiddle.net/5qbG6/6/

回答by bgs

Try This:

试试这个:

$("input[name='RadioButtonId']:checked").val()

$.get('burgerorder_check.php', function(data) {
                inputVal = $("input[name='timeslot']:checked").val()
            });

回答by bgs

var timeslot = $("#timeslot:checked").val();
alert(timeslot );