JavaScript implements select all and unselect all operations

JavaScript implements select all and unselect all operations

This article shares the specific code for JavaScript to implement the select all and unselect all operations for your reference. The specific content is as follows

Effect examples

By default:

When Select All is checked:

When you uncheck item A/item B/item C at will

Implementation Code

<!DOCTYPE html>
<html>

 <head>
  <meta charset="UTF-8">
  <title>Select All</title>
  <script>
   function myAll() {
    var all = document.getElementById("all");
    var oneList = document.getElementsByName("one");
    for(var i = 0; i < oneList.length; i++) {
     oneList[i].checked = all.checked;
    }
   }

   function myOne() {
    var all = document.getElementById("all");
    var oneList = document.getElementsByName("one");
    for(var i = 0; i < oneList.length; i++) {
     if(oneList[i].checked == false) {
      all.checked = false;
      return;
     }
    }
    all.checked = true;
   }
  </script>
 </head>

 <body>
  <table id="myTable" border="1" cellpadding="0" cellspacing="0" width="90%" height="180px">
   <tr>
    <th>Select All<input id="all" type="checkbox" onclick="myAll()" /></th>
    <th>Serial number</th>
    <th>Name</th>
    <th>Unit Price</th>
    <th>Quantity</th>
    <th>Total</th>
   </tr>
   <tr>
    <td><input name="one" type="checkbox" onclick="myOne()" /></td>
    <td>1</td>
    <td>Item A</td>
    <td>¥55</td>
    <td>1</td>
    <td>¥55</td>
   </tr>
   <tr>
    <td><input name="one" type="checkbox" onclick="myOne()" /></td>
    <td>2</td>
    <td>Item B</td>
    <td>¥70</td>
    <td>1</td>
    <td>¥70</td>
   </tr>
   <tr>
    <td><input name="one" type="checkbox" onclick="myOne()" /></td>
    <td>3</td>
    <td>Item C</td>
    <td>¥66</td>
    <td>1</td>
    <td>¥66</td>
   </tr>
  </table>
 </body>

</html>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • js to achieve all selection and none selection
  • js realizes the function of selecting all and deselecting all
  • Js implements the checkbox select all, unselect all and reverse selection function code example
  • JS implementation of "select all" and "unselect all" function code examples
  • Native JS version and jQuery version to achieve checkbox selection/unselect/select/select in line (Mr.Think)
  • JS implements the function of selecting all, unselecting or unselecting all checkboxes
  • How to select all/unselect all checkboxes using js and jQuery
  • JS implements the function of selecting all and deselecting all in CheckBox
  • How to use js to select all or unselect all
  • Another way to implement jquery select all/unselect all/invert (with native js)

<<:  Detailed explanation of the process of deploying MySql on Centos server and connecting to Navicat

>>:  Quickly learn MySQL basics

Recommend

MySQL 5.7.21 winx64 installation and configuration method graphic tutorial

This article summarizes the notes for installing ...

Detailed steps to install xml extension in php under linux

Installing XML extension in PHP Linux 1. Enter th...

Solution to web page confusion caused by web page FOUC problem

FOUC is Flash of Unstyled Content, abbreviated as ...

Method of building docker private warehouse based on Harbor

Table of contents 1. Introduction to Harbor 1. Ha...

SQL implementation of LeetCode (197. Rising temperature)

[LeetCode] 197.Rising Temperature Given a Weather...

mysql splits a row of data into multiple rows based on commas

Table of contents Separation effect Command line ...

Three ways to implement text color gradient in CSS

In the process of web front-end development, UI d...

Basic usage tutorial of IPTABLES firewall in LINUX

Preface For production VPS with public IP, only t...

Navigation Design and Information Architecture

<br />Most of the time when we talk about na...

Docker link realizes container interconnection

Table of contents 1.1. Network access between con...

Writing daily automatic backup of MySQL database using mysqldump in Centos7

1. Requirements: Database backup is particularly ...

In-depth explanation of MySQL stored procedures (in, out, inout)

1. Introduction It has been supported since versi...

JavaScript to show and hide images

JavaScript shows and hides pictures, for your ref...

Pure CSS to implement iOS style open and close selection box function

1 Effect Demo address: https://www.albertyy.com/2...