Check whether specific radio button is checked

后端 未结 7 1048
忘掉有多难
忘掉有多难 2020-12-14 01:10

I\'m having trouble after looking at the jQuery docs. I\'m just trying to return true/false in one my my jquery methods depending on the check of a certain radiobutton and

7条回答
  •  [愿得一人]
    2020-12-14 01:12

    Just found a proper working solution for other guys,

    // Returns true or false based on the radio button checked
    $('#test1').prop('checked')
    
    
    $('body').on('change','input[type="radio"]',function () {
    alert('Test1 checked = ' + $('#test1').prop('checked') + '. Test2 checked = ' + $('#test2').prop('checked') + '. Test3 checked = ' + $('#test3').prop('checked'));
    });
    
    
    
    
    
    
     

    and in your method you can use like

    return $('#test2').prop('checked');
    

提交回复
热议问题