JavaScript to achieve all or reverse selection function

JavaScript to achieve all or reverse selection function

This article shares the specific code of JavaScript to achieve the function of selecting all or inverting selection for your reference. The specific content is as follows

The code is as follows

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Case--Select All Tables</title>
    <style>
        table {
            border: 1px solid;
            margin: auto;
            width: 500px;
        }

        td, th {
            text-align: center;
            border: 1px solid;
        }

        .out {
            background-color: white;
        }

        .over {
            background-color: pink;
        }
        div{
            margin-top: 10px;
            text-align: center;
        }
    </style>
    <script>
        window.onload = function () {
            //Select all document.getElementById("checkAll").onclick = function () {
                var cbs = document.getElementsByName("cb");
                for (var i = 0; i < cbs.length; i++) {
                    cbs[i].checked = true;
                }
            }
            //Uncheck all document.getElementById("unCheckAll").onclick = function () {
                var cbs = document.getElementsByName("cb");
                for (var i = 0; i < cbs.length; i++) {
                    cbs[i].checked = false;
                }
            }
            //Recheck document.getElementById("reCheck").onclick = function () {
                var cbs = document.getElementsByName("cb");
                for (var i = 0; i < cbs.length; i++) {
                    cbs[i].checked = !cbs[i].checked;
                }
            }

            //When the mouse passes over, the color changes var trs = document.getElementsByTagName("tr");
            for (var i = 0; i < trs.length; i++) {
                trs[i].onmouseover = function () {
                    this.className = "over";
                }
                trs[i].onmouseout = function () {
                    this.className = "out";
                }
            }

            //Select the top checkbox and select all document.getElementById("firstCb").onclick = function () {
                var cbs = document.getElementsByName("cb");
                for (var i = 0; i < cbs.length; i++) {
                    cbs[i].checked = this.checked;
                }
            }

        }

    </script>
</head>
<body>
<table>
    <caption>Student Information Form</caption>
    <tr>
        <td><input type="checkbox" name="cb" id="firstCb"></td>
        <td>Number</td>
        <td>Name</td>
        <td>Gender</td>
        <td>Operation</td>
    </tr>
    <tr>
        <td><input type="checkbox" name="cb"></td>
        <td>1</td>
        <td>Linghu Chong</td>
        <td>Male</td>
        <td><a href="javascript:void(0);" onclick="delTr(this)">Delete</a></td>
    </tr>

    <tr>
        <td><input type="checkbox" name="cb"></td>
        <td>2</td>
        <td>Let me go</td>
        <td>Male</td>
        <td><a href="javascript:void(0);" onclick="delTr(this)">Delete</a></td>
    </tr>

    <tr>
        <td><input type="checkbox" name="cb"></td>
        <td>3</td>
        <td>Yue Buqun</td>
        <td>?</td>
        <td><a href="javascript:void(0);" onclick="delTr(this)">Delete</a></td>
    </tr>
</table>
<div>
    <input type="button" value="Select All" id="checkAll">
    <input type="button" value="Uncheck All" id="unCheckAll">
    <input type="button" value="Recheck" id="reCheck">
</div>


</body>
</html>

Operation Results

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 checkbox all selection and inverse selection example
  • js implements the method of selecting all, unselecting and inverting checkboxes
  • AngularJS implements the function of selecting all and deselecting
  • javascript checkbox select all/deselect all and delete in batches
  • Using Vue.js to achieve the effect of all selection and reverse selection of checkbox
  • Compatible with IE and Firefox versions of js to reverse the selection of all checkboxes
  • JavaScript implements simple select all and inverse select functions
  • js html css to achieve checkbox all selection and inverse selection
  • Detailed explanation of javascript to implement checkbox select all and reverse select events
  • js operates CheckBoxList to select all/deselect all (completed on the client side)

<<:  MySQL practical skills: analysis of methods to compare whether two tables have different data

>>:  Remote development with VSCode and SSH

Recommend

Detailed explanation of how to pass password to ssh/scp command in bash script

Install SSHPASS For most recent operating systems...

Parse CSS to extract image theme color function (tips)

background It all started when a classmate in the...

HTML form value transfer example through get method

The google.html interface is as shown in the figur...

How to create a MySQL database (de1) using commands

1. Connect to MYSQL Format: mysql -h host address...

Detailed explanation of encoding issues during MySQL command line operations

1. Check the MySQL database encoding mysql -u use...

The url value of the src or css background image is the base64 encoded code

You may have noticed that the src or CSS backgroun...

Introduction to JavaScript strict mode use strict

Table of contents 1. Overview 1.1 What is strict ...

Installation method of mysql-8.0.17-winx64 under windows 10

1. Download from the official website and unzip h...

How to install and deploy ftp image server in linux

Refer to the tutorial on setting up FTP server in...

MySQL trigger definition and usage simple example

This article describes the definition and usage o...

Thinking about grid design of web pages

<br />Original address: http://andymao.com/a...

HTML table markup tutorial (16): title horizontal alignment attribute ALIGN

By default, the table title is horizontally cente...

Getting Started Tutorial for Beginners: Domain Name Resolution and Binding

So after registering a domain name and purchasing...

How to automatically import Vue components on demand

Table of contents Global Registration Partial Reg...

Basic ideas and codes for implementing video players in browsers

Table of contents Preface Summary of audio and vi...