JS How to implement the name is an array of the check box to select and reverse the selection and deselect? The form contents are as follows:
Because PHP receives a check box in the form of an array, JQ can normally be
Use $ ("INPUT[NAME=PTPT") directly. But this PHP receives only the last value, the string.
<label><input type= ' checkbox ' name= ' ptpt ' value= ' A1 '/>a1</label>
<label><input type= ' checkbox ' name= ' ptpt ' value= ' A3 '/>a3</label>
<label><input type= ' checkbox ' name= ' ptpt ' value= ' A6 '/>a6</label>
<label><input type= ' checkbox ' name= ' ptpt ' value= ' A9 '/>a9</label>
So PHP is receiving an array of ptpt.
<form method= "Post" id= "Form1" Name= "Form1" action= "" >
<label><input type= ' checkbox ' name= ' ptpt[1] ' value= ' A1 '/>a1</label>
<label><input type= ' checkbox ' name= ' ptpt[3] ' value= ' A3 '/>a3</label>
<label><input type= ' checkbox ' name= ' ptpt[6] ' value= ' A6 '/>a6</label>
<label><input type= ' checkbox ' name= ' ptpt[9] ' value= ' A9 '/>a9</label>
<input type= "button" value= "Select All" onclick= "" >
<input type= "button" value= "reverse" onclick= "" >
<input type= "button" value= "Deselect All" onclick= "" >
<script src= "Jquery-1.7.2.min.js" ></script>
<script>
$ (function () {
var chks = $ (': checkbox[name^= "ptpt["] '); //Match the part whose name starts with ptpt[
$ (': Button:eq (0) '). Click (function () {
chks.attr (' checked ', ' checked ');
})
$ (': Button:eq (1) '). Click (function () {
Chks.each (function () {
if ($ (this). attr (' checked ') = = ' checked ')
$ (this). Removeattr (' checked ');
Else
$ (this). attr (' checked ', ' checked ');
});
})
$ (': Button:eq (2) '). Click (function () {
chks.removeattr (' checked ');
})
})
</script>
JS How to implement the check box for name is an array select all and deselect and unselect