Radio buttons not checked in jQuery

前端 未结 7 678
盖世英雄少女心
盖世英雄少女心 2020-12-23 08:51

I have this line of code for page load:

if ($(\"input\").is(\':checked\')) {

and it works fine when the radio button input is checked. How

相关标签:
7条回答
  • 2020-12-23 09:36

    This works too. It seems shortest working notation: !$('#selector:checked')

    0 讨论(0)
  • 2020-12-23 09:37

    If my firebug profiler work fine (and i know how to use it well), this:

    $('#communitymode').attr('checked')
    

    is faster than

    $('#communitymode').is('checked')
    

    You can try on this page :)

    And then you can use it like

    if($('#communitymode').attr('checked')===true) { 
    // do something
    }
    
    0 讨论(0)
  • 2020-12-23 09:38
    $('input:radio[checked=false]');
    

    this will also work

    input:radio:not(:checked)
    

    or

    :radio:not(:checked)
    
    0 讨论(0)
  • $("input").is(":not(':checked')"))
    

    This is jquery 1.3, mind the ' and " signs!

    0 讨论(0)
  • 2020-12-23 09:46
    (!$('#radio').is(':checked'))
    

    This worked for me

    0 讨论(0)
  • 2020-12-23 09:52
    if ( ! $("input").is(':checked') )
    

    Doesn't work?

    You might also try iterating over the elements like so:

    var iz_checked = true;
    $('input').each(function(){
       iz_checked = iz_checked && $(this).is(':checked');
    });
    if ( ! iz_checked )
    
    0 讨论(0)
提交回复
热议问题