jQuery - ensuring all radio groups are checked

前端 未结 3 708
深忆病人
深忆病人 2021-01-18 09:34

I\'d like to loop through multiple (dynamic) radio button groups using jQuery, and if any haven\'t had a selection made, it throws up an error and stops the form submission.

3条回答
  •  再見小時候
    2021-01-18 10:08

    I've accidentally just found even more elegant solution! It is only useful when you know the exact count of radio buttons.

    var x = 0;
    
    $(":radio").change(function() {
    x = x + 1;
    
    if (x == count) {
    
    //do smth
    
    }
    
    });
    

提交回复
热议问题