JS gets the number of marquee checkboxes selected.
var checkbox = Document.getelementsbyname ("likes[]");
This is the way to get multiple-selection boxes to be arrays.
//like is name = "like[]" and must be added []
var checked_counts = 0;
for (Var i=0;i<checkbox.length;i++) {
if (checkbox[i].checked) { //Selected checkbox
checked_counts++
}
alert (checked_counts);
What I do is that every click on a multiple selection box to determine whether the current number of checked more than a certain number
function Checkdate () {
var n = $ ("#cart_q_num"). Val ();
var checkedcount=0;
var checkbox = Document.getelementsbyname ("tie_in[]");
alert (checkbox.length);
for (Var i=0;i<checkbox.length i + +) {
if (checkbox[i].checked) {
checkedcount++
}}
}
alert (checkedcount);
if (checkedcount>n) {
alert ("The quantity of the gifts should equal to the quantity of the sunglasses set.");
return false;
} else{
$ ("#free_pro_selected_num"). HTML (checkedcount);
}
To make the function checkdata () Work every click, you need to add the onclick event in the checkbox box:
The above JS to get the number of the checkbox is a simple example is a small series to share all the content, I hope to give you a reference, but also hope that we support the cloud-dwelling community.