Common checkbox operations, checkbox
Select All (based on the check option selected, set all or all of the checkboxes to be deselected)
function SelectAll(checked,checkbox_id) {var checkboxs=document.getElementsByName(checkbox_id);for (var i=0;i<checkboxs.length;i++) { var e=checkboxs[i]; e.checked=checked;}}
Call code:
<input type="checkbox" value="" onClick="SelectAll(this.checked,'guaranteeNumber');"/>
Batch Reverse Selection
function SelectAll(checkbox_id) { var checkboxs=document.getElementsByName(checkbox_id); for (var i=0;i<checkboxs.length;i++) { var e=checkboxs[i]; e.checked=!e.checked; }}
Concatenate a string
Function getChoosedGuaranteeNumber () {var ids = ""; $ ('input [name = "guaranteeNumber"]: checked '). each (function () {ids + = $ (this ). val () + '_';}); // remove the special character if (ids. indexOf ("_")>-1) {ids = ids. substring (0, ids. length-1);} return ids ;}
Parse the string and set the selected items in the checkbox.
(If there are many options, it may be efficient)
var guaranteeNumberIds = $("#guaranteeNumberIds").val()var array2 = guaranteeNumberIds.split('_')for (var i=0; i<array2.length; i++){ var nuberValue = array2[i]; $('input[name="guaranteeNumber"]').each(function(){ if($(this).val() == nuberValue){ $(this).attr("checked","true"); } }); }
Js operations on checkbox
Js does not have a two-dimensional Array, but the Array Object is an Object, which can contain anything,
The two-dimensional Array in js is, Array sets the Array
You can choose to use two Arrays
<HTML>
<HEAD>
</HEAD>
<Script language = "JavaScript">
<! --
Function fun (){
Var arr1 = new Array ();
Var arr2 = new Array ();
Var boxObj = document. getElementsByName ("chkBox ");
Var str = "";
Var index = 0;
For (I = 0; I <boxObj. length; I ++ ){
If (boxObj [I]. checked ){
Arr1 [index] = I + 1;
Arr2 [index ++] = boxObj [I]. value;
}
}
For (I = 0; I <arr1.length; I ++ ){
Str + = arr1 [I] + "" + arr2 [I] + "<br> ";
}
Document. getElementById ("txt"). innerHTML = str;
}
// -->
</SCRIPT>
<BODY>
<Input type = "button" name = "btn" value = "click" onclick = "fun ();"> <br>
<Input type = "checkbox" name = "chkBox" value = "a"> 1 a <br>
<Input type = "checkbox" name = "chkBox" value = "B"> 1 B <br>
<Input type = "checkbox" name = "chkBox" value = "c"> 1 c <br>
<Input type = "checkbox" name = "chkBox" value = "d"> 1 d <br>
<Input type = "checkbox" name = "chkBox" value = "e"> 1 e <br>
<Input type = "checkbox" name = "chkBox" value = "f"> 1 f <br>
<Div id = "txt"> </div>
</BODY>
</HTML>... the remaining full text>
Html: checkbox multiple choice
Set the name attribute of the checkbox to the same
For example:
<Form id = "form1" name = "form1" method = "post" action = "">
<Input name = "love" type = "checkbox" id = "aa" value = "Music"/>
<Input name = "love" type = "checkbox" id = "aa" value = "motion"/>
</Form>
In this way, the submitted love is a set of values.