This article mainly introduces JavaScript using Shift+click to implement selection and reverse checkbox, involving JavaScript for keyboard keys and checkbox operation skills, need friends can refer to the
This article illustrates how JavaScript uses Shift+click to implement select and Reverse CheckBox selection. Share to everyone for your reference. The implementation methods are as follows:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20-21 |
var lastchecked = null; var handlechecked = function (e) {if (lastchecked && e.shiftkey) {var i = $ (' input[type= checkbox '] '). Index (Lastch ecked); 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[typ e= "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 will help you with your JavaScript programming.