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:
|
<<: MySQL practical skills: analysis of methods to compare whether two tables have different data
>>: Remote development with VSCode and SSH
Table of contents Preface: 1. Understand lock wai...
Table of contents 1. Install the psutil package S...
1. Related concepts 1.1 Jenkins Concepts: Jenkins...
After writing these six articles, I started to fee...
Table of contents 1. Project Requirements Second,...
MySQL is a relational database management system ...
When a user registers, they will click on a label...
Table of contents Docker images What is a mirror?...
The RHEL/CentOS series of Linux operating systems...
introduce If you are using an OSS storage service...
Preface The essence of deadlock is resource compe...
Table of contents Foreign Key How to determine ta...
Most websites nowadays have long pages, some are ...
Harbor is an enterprise-level registry server for...
1. Install Tomcat 1. Find the tomcat image on Doc...