javascript - Select Multiple Checkboxes By Cntrl + Click -
i have form has many checkbox elements lined in rows. implement function allows user hold cntrl, select checkbox , have every box either:
a) become checked there no initial box checked
b) become checked closest checked box
is possible? many thanks.
this .
the code shift+key
// usage: $form.find('input[type="checkbox"]').shiftselectable(); // replace input[type="checkbox"] selector match list of checkboxes $.fn.shiftselectable = function() { var lastchecked, $boxes = this; $boxes.click(function(evt) { if(!lastchecked) { lastchecked = this; return; } if(evt.shiftkey) { var start = $boxes.index(this), end = $boxes.index(lastchecked); $boxes.slice(math.min(start, end), math.max(start, end) + 1) .attr('checked', lastchecked.checked) .trigger('change'); } lastchecked = this; });
};
credits : jquery plugin shift + click select multiple checkboxes
Comments
Post a Comment