Determine if every radio group has had an option selected

后端 未结 6 1918
南旧
南旧 2020-12-21 02:18

I need to make sure that all the radio groups have been answered before I enable the submit button. If I have:

var radioBtns = $(\'input\').filter(\':radio\         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 02:46

    This works:

    var all_answered = true;
    $(':radio').each(function(){
        if($(':radio[name='+$(this).attr('name')+']:checked').length == 0)
        {
            all_answered = false;
        }
    });
    alert(all_answered);
    

    Working demo: http://jsfiddle.net/AlienWebguy/8Cu6d/1/

提交回复
热议问题