mercredi 27 janvier 2016

jQuery - Check if a group of Check Boxes are checked

How do I check if any of the Check Boxes in chkInv* (chkInv1 and chkInv2) are checked and exclude chkUnrelated.

<label for="chkInv2-0">
  <input name="chkInv2" id="chkInv2-0" type="checkbox" value="1">
  chkInv2
</label>

<label for="chkInv2-1">
  <input name="chkInv2" id="chkInv2-1" type="checkbox" value="2">
  chkInv2
</label>

<label for="chkInv3-0">
  <input name="chkInv3" id="chkInv3-0" type="checkbox" value="3">
  chkInv3
</label>

<label for="chkInv3-1">
  <input name="chkInv3" id="chkInv3-1" type="checkbox" value="4">
  chkInv3
</label>

<label for="chkUnrelated">
  <input name="chkUnrelated" id="chkUnrelated-1" type="checkbox" value="4">
  chkUnrelated
</label>

My current code checks all the Check Boxes of the page.

var checkBoxes = $('input:checkbox:checked').length;

Can I use some kind of regular expression?

var checkBoxes = $('input:checkbox[name=chkInv*]:checked').length;




Aucun commentaire:

Enregistrer un commentaire