JQuery Select Checkboxes
I am using jQuer开发者_运维知识库y.
I have a list of radio buttons which I am getting this way:
var $selectAllRadios = $('input:radio[value=select]');
Now in this list I want to be able to select all the radio buttons which are currently checked and also the number of radio buttons that are currently checked.
How can I achieve this?
Use the :checked
selector to grab the selected radio buttons, and the length
property to find out how many there are.
var $checkedRadios = $('input:radio[value=select]:checked');
var count = $checkedRadios.length;
This is a duplicated, you should search the site before asking a question:
Radio button selected?
How to know if radio is checked
As for the number of elements you can always use the length property.
Use this to get the length
of the radio buttons that are checked.
$('input:radio[value=select]').filter(':checked').length
To get the length
of radio butons that are not checked.
$('input:radio[value=select]').filter(':not(:checked)').length
精彩评论