javascript USES shift+click to implement the select and de select checkbox methods
- 2020-06-03 05:50:57
- OfStack
This article illustrates javascript's method of using shift+click to select and de-select checkbox. Share to everybody for everybody reference. Specific implementation methods are as follows:
var lastChecked = null;
var handleChecked = function(e) {
if(lastChecked && e.shiftKey) {
var i = $('input[type="checkbox"]').index(lastChecked);
var j = $('input[type="checkbox"]').index(e.target);
var checkboxes = [];
if (j > i) {
checkboxes = $('input[type="checkbox"]:gt('+ (i-1) +'):lt('+(j-i)+')');
} else {
checkboxes = $('input[type="checkbox"]:gt('+ j +'):lt('+ (i-j) +')');
}
if (!$(e.target).is(':checked')) {
$(checkboxes).removeAttr('checked');
} else {
$(checkboxes).attr('checked', 'checked');
}
}
lastChecked = e.target;
// Other click action code.
}
$('input[type=checkbox]').click(handleChecked);
I hope this article has been helpful for your javascript programming.