html - Limit number of checkboxes to be selected, jQuery -
a simpler version of question has been posted, i'm having difficulty.
say have 5 checkboxes:
- none
- apple
- banana
- orange
- pear
the user allowed select 2 checkboxes, if "none" chosen, can select one.
is possible @ all?
try play example:
var checked = [], $check = $('.check').change(function() { if (this.value == -1 && this.checked) { $check.not(this).prop('disabled', true).prop('checked', false); checked = []; } else { $check.prop('disabled', false); checked.push(this); checked = $(checked) checked.prop('checked', false).slice(-2).prop('checked', true); } });
Comments
Post a Comment