Example code of javascript select all/unselect all operation in html

Example code of javascript select all/unselect all operation in html

Copy code
The code is as follows:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">
function selectAllDels()
{
var allCheckBoxs = document.getElementsByName("preDelCheck");
var desc = document.getElementById("allChecked");
var selectOrUnselect=false;
for(var i = 0; i < allCheckBoxs.length; i ++ )
{
if(allCheckBoxs[i].checked){
selectOrUnselect=true;
break;
}
}
if (selectOrUnselect)
{
_allUnchecked(allCheckBoxes);
}else
{
_allchecked(allCheckBoxes);
}
}
function _allchecked(allCheckBoxes){
for(var i = 0; i < allCheckBoxs.length; i ++ )
{
allCheckBoxs[i].checked = true;
}
}
function _allUnchecked(allCheckBoxes){
for(var i = 0; i < allCheckBoxs.length; i ++ )
{
allCheckBoxs[i].checked = false;
}
}
</script>
</head>
<body>
<p>test</p>
<form>
<input type="checkbox" name="preDelCheck" value="cream">ID1

<input type="checkbox" name="preDelCheck" value="sugar" >ID2

<input type="checkbox" name="preDelCheck" value="sugar">ID3

<input type="checkbox" name="preDelCheck" value="sugar">ID4

<input type="checkbox" name="preDelCheck" value="sugar">ID5

<input type="button" id="allChecked" value="Select all/Unselect all" onClick="selectAllDels()">
</form>
</body>
</html>

<<:  How to install and deploy zabbix 5.0 for nginx

>>:  Detailed explanation of single-row function code of date type in MySQL

Recommend

Solution to the garbled code problem in MySQL 5.x

MySQL is a commonly used open source database sof...

How to use multi-core CPU to speed up your Linux commands (GNU Parallel)

Have you ever had the need to compute a very larg...

Detailed explanation of Vue custom instructions

Table of contents Vue custom directive Custom dir...

React Native scaffolding basic usage detailed explanation

Build the project Execute the command line in the...

jQuery realizes image highlighting

It is very common to highlight images on a page. ...

MySQL 8.0.22 installation and configuration graphic tutorial

MySQL8.0.22 installation and configuration (super...

How to create a stylish web page design (graphic tutorial)

"Grand" are probably the two words that ...

Native js encapsulation seamless carousel function

Native js encapsulated seamless carousel plug-in,...

The difference between VOLUME and docker -v in Dockerfile

There are obvious differences between volume moun...

Sample code for installing ASPNET.Core3.0 runtime in Linux

# The following examples are for x64-bit runtime ...

Record a troubleshooting record of high CPU usage of Tomcat process

This article mainly records a tomcat process, and...

Complete steps for vue dynamic binding icons

0 Differences between icons and images Icons are ...

CSS pseudo-element::marker detailed explanation

This article will introduce an interesting pseudo...