Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize full selection, cancellation and cross-page saving of CHECKBOX

Shulou Source: shulou.com Published: 2022-06-03 07:38:21 09月17日 Update

This article focuses on "how to achieve full selection, cancellation and cross-page saving of CHECKBOX". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to achieve full selection, cancellation and cross-page saving of CHECKBOX"!

The copy code is as follows:

$(document) .ready (function () {

/ * *

* Select all checkbox

, /

$(".checkall") .live ("click", function () {

If ($(this) .attr ("checked") = = "checked") {/ / if selected

CheckAll ()

} else {

UnCheckAll ()

}

UpdateHfValues ()

});

$(".checkone") .each (function () {

$(this) .live ("click", function () {

CheckOne ()

UpdateHfValues ()

});

});

Function UnCheckAll () {

/ / deselect all

$(".checkone") .each (function () {

$(this) .removeAttr ("checked")

});

}

Function CheckAll () {

/ / Select all

$(".checkone") .each (function () {

$(this) .attr ("checked", "checked")

});

}

Function CheckOne () {

/ / check whether to select all when clicking a single message

Var $length = $(".checkone") .length

Var $checklenght = $(".checkone: checked") .length

If ($length = = $checklenght) {

$(".checkall") .attr ("checked", "checked")

} else {

$(".checkall") .removeAttr ("checked")

}

}

Var arr = ("# hfDel") .val () .split (",")

$(".checkone") .each (function () {

Var I = 0

For (I = 0; I)

< arr.length; i++) { if (arr[i] == $(this).val()) { $(this).attr("checked", "checked"); } } }); var checkedNum = $(".checkone:checked").length; var allNum = $(".checkone").length; if (checkedNum == allNum) { $(".checkall").attr("checked", "checked"); } function UpdateHfValues() { var $checkOneLen = $(".checkone:checked").length; var $conVal = ""; $(".checkone:checked").each(function (i) { $conVal += $(this).val() + ","; }); if ($conVal.length >

0) {

$conVal = $conVal.substring (0, $conVal.length-1)

}

$conVal = $conVal + "," + $("# hfDel"). Val ()

Var allArray = $conVal.split (, ")

$(".checkone") .each (function () {

If (typeof $(this) .attr ("checked")! = "undefined" & & $(this) .attr ("checked") = = "checked") {

Var I = 0

Var find = false

For (I = 0; I)

< allArray.length; i++) { if (allArray[i] == $(this).val()) { find = true; } } if (find == false) { allArray.push($(this).val()); } } else { var i = 0; for (i = 0; i < allArray.length; i++) { if (allArray[i] == $(this).val()) { allArray[i] = ""; } } } }); var i = 0; var result = ""; for (i = 0; i < allArray.length; i++) { if (allArray[i] != "") { result += allArray[i] + ","; } } if (result.length >

0) {

Result = result.substring (0, result.length-1)

}

$("# hfDel") .val (result)

}

Function UpdateValues () {

Alert ($("# hfDel") .val ())

Var $checkOneLen = $(".checkone: checked") .length

Var $conVal = ""

$(".checkone: checked") .each (function (I) {

$conVal + = $(this). Val () + ","

});

$conVal = $conVal.substring (0, $conVal.length-1)

("# hfDel") .val ($conVal)

}

$("# btnDeletes"). Unbind ("click"). Live ("click", function () {

If ($("# hfDel") .val ()! = ") {

If (confirm ("are you sure you want to enable the selected option?") {

Return true

} else {

Return false

}

} else {

Alert ("you have not selected the option to enable!")

Return false

}

});

$("# lbTingYong"). Unbind ("click"). Live ("click", function () {

If ($("# hfDel") .val ()! = ") {

If (confirm ("are you sure you want to disable the selected option?") {

Return true

} else {

Return false

}

} else {

Alert ("you have not selected the option to deactivate!")

Return false

}

});

});

Tags: Code content not yet learning practical deeper interested practical practical easy to operate methods more friends messages websites channels inquiries tests Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Docker Shulou Information MySQL OPPO Reno