


Javascript implements email display and deletion functions_javascript skills
1. Main introduction:
This question uses the previous technology, based on the rows attribute of the table, obtains the array, and then sets the style on the array, so the color comes out.
1). Select all check boxes , pass var nodess=document.getElementsByName("mail");
for(var x=0;x<nodess.length;x++){ nodess[x].checked=nodes.checked; }
Checkbox function
2). The button selects all, inverts the selection, and deselects all. can be written with a function, and different parameter AllBybtn (num) types can be passed in
In the function, the two states of non-0 and 0 are set according to the characteristics of js. For synchronization, they need to be set separately
3).In order to display that all check boxes are selected by default when all are selected, it is necessary to set each check box and use the function checkBysingle() to set it
4).It is necessary to delete the selected item. The current one is the checkbox object. The upper level is td--tr--get the tr object first, and then delete the tr from the parent node passing tr. After the object is deleted, x will change, and some objects may not be deleted, so you need to restore the value of X or delete it from the back.
2. Style setting:
<style type="text/css"> .one{ background-color:#00ff80; } .two{ background-color:#80ff00; } .three{ background-color:#0000ff; } table th{ background-color:#c0c0c0; } table{ width:400px; border:solid 1px; } table tr{ height:50px; } </style>
3. Background color and mouse movement event settings
function toaddcolor(){ //颜色设置, var nodes = document.getElementById("tabid"); var rows1 = nodes.rows; for (var x = 1; x < rows1.length; x++) { if (x % 2 == 0) { rows1[x].className = "one"; } else { rows1[x].className = "two"; } } } function addEvent(){ var name; //当鼠标移上去之后发生相应的变化 var nodes=document.getElementById("tabid"); var rows1=nodes.rows; for (var x = 1; x < rows1.length; x++) { rows1[x].onmouseover = function(){ name = this.className; this.className = "three"; } rows1[x].onmouseout = function(){ this.className = name; } // alert("bb"); // alert(rows1[x].getElementsByTagName("input")[0].nodeName); rows1[x].getElementsByTagName("input")[0].onclick=function(){//每一行的input对象 document.getElementsByName("allItem")[0].indeterminate=true;//让全选的复选框形状发生变化 } } } onload=function(){//在网页加载时候调用 toaddcolor(); addEvent(); }
4. Select all check boxes
function allcheck(nodes){//全选checkbox的点击调用这个 var nodess=document.getElementsByName("mail"); for(var x=0;x<nodess.length;x++){ nodess[x].checked=nodes.checked; } //多个全选的时候,必须和其他的一个一样 var nodes1=document.getElementsByName("allItem"); for(var x=0;x<nodes1.length;x++){ nodes1[x].checked=nodes.checked; } }
5. Select all buttons
function AllBybtn(num){//全选按钮设置 var nodess = document.getElementsByName("mail"); /*多重for 循环不太好,可以根据js里面的特性0 非0 for (var x = 0; x < nodess.length; x++) { if (num == 1) { nodess[x].checked = 1; }else if (num == 2) { nodess[x].checked = !nodess[x].checked; }else if (num == 3) { nodess[x].checked = false; } }*/ for(var x=0;x<nodess.length;x++){ if(num<2){ nodess[x].checked=num; //让全选的复选框可以 单独写个函数 var all=document.getElementsByName("allItem"); for(var y=0;y<all.length;y++){ if(num==1){ all[y].checked=num; }else{ all[y].checked=num; } } }else{ nodess[x].checked=!nodess[x].checked; var all=document.getElementsByName("allItem"); for (var y = 0; y < all.length; y++) { all[y].checked=0; }}}}
6. After all items are selected, select them all and select them automatically
function checkBysingle(){//全部入选之后,全选的自动选中 var flag = true; var node = document.getElementsByName("mail"); for (var x = 0; x < node.length; x++) { if (node[x].checked == false) { flag = false; break; } } var all = document.getElementsByName("allItem"); for (var y = 0; y < all.length; y++) { if (flag) { all[y].checked = true; } else { all[y].checked = false; }}}
7. Function to delete emails (delete rows)
function DelBybtn(){//删除行 var tdnode=document.getElementsByName("mail"); /*for(var x=0;x<tdnode.length;x++){ if(tdnode[x].checked){//对象是 checkbox 我们必须要那父级的父级 《tr》,我们需要移除的就是tr对象 var trnode=tdnode[x].parentNode.parentNode;//tr对象 trnode.parentNode.removeChild(trnode);//table对象移除tr对象 // alert("aa"); //节点容器跟Java当中的集合一样,只要是remove(),长度就会变的。这里,需要进行x的复位 x--; }*/ for(var x=tdnode.length-1;x>=0;x--){ if(tdnode[x].checked){//对象是 checkbox 我们必须要那父级的父级 《tr》,我们需要移除的就是tr对象 var trnode=tdnode[x].parentNode.parentNode;//tr对象 trnode.parentNode.removeChild(trnode);//table对象移除tr对象 } loading();//调用颜色的设置 } }
Phenomena 1:
Reverse election effect:
Before deletion:
After deletion:
Full code:
<!DOCTYPE html> <html> <head> <!-- 这题采用之前的技术,根据table的rows属性,获得数组,然后对数组设置样式,所以颜色就出来了 1,全选复选框,通过var nodess=document.getElementsByName("mail"); for(var x=0;x<nodess.length;x++){ nodess[x].checked=nodes.checked; } 复选框函数进行 2,按钮全选,反选,和取消全选,可以用一个函数写,传入不同的参数AllBybtn(num)类型即可 函数里面 根据js的特性 非0 和 0 这两种状态,进行设置,为了同步,需要分别进行设置 3,为了显示出当全部选中就默认全选的复选框选中,所以需要对每一个复选框进行设置,采用函数checkBysingle()进行设置 4,删除所选项是需要主要,当前的是checkbox对象,上一级是td--tr--先拿到tr对象,然后对通过tr的父节点删除tr对象 再删除之后,x会变化,可能有些删不到,所以需要将X的值还原,或者从后面开始删除 --> <title>Mail.html</title> <style type="text/css"> .one{ background-color:#00ff80; } .two{ background-color:#80ff00; } .three{ background-color:#0000ff; } table th{ background-color:#c0c0c0; } table{ width:400px; border:solid 1px; } table tr{ height:50px; } </style> <script type="text/javascript"> var name; function toaddcolor(){ //颜色设置, var nodes = document.getElementById("tabid"); var rows1 = nodes.rows; for (var x = 1; x < rows1.length; x++) { if (x % 2 == 0) { rows1[x].className = "one"; } else { rows1[x].className = "two"; } } } function addEvent(){ var name; //当鼠标移上去之后发生相应的变化 var nodes=document.getElementById("tabid"); var rows1=nodes.rows; for (var x = 1; x < rows1.length; x++) { rows1[x].onmouseover = function(){ name = this.className; this.className = "three"; } rows1[x].onmouseout = function(){ this.className = name; } // alert("bb"); // alert(rows1[x].getElementsByTagName("input")[0].nodeName); rows1[x].getElementsByTagName("input")[0].onclick=function(){//每一行的input对象 document.getElementsByName("allItem")[0].indeterminate=true;//让全选的复选框形状发生变化 } } } onload=function(){//在网页加载时候调用 toaddcolor(); addEvent(); } function allcheck(nodes){//全选checkbox的点击调用这个 var nodess=document.getElementsByName("mail"); for(var x=0;x<nodess.length;x++){ nodess[x].checked=nodes.checked; } //多个全选的时候,必须和其他的一个一样 var nodes1=document.getElementsByName("allItem"); for(var x=0;x<nodes1.length;x++){ nodes1[x].checked=nodes.checked; } } function AllBybtn(num){//全选按钮设置 var nodess = document.getElementsByName("mail"); /*多重for 循环不太好,可以根据js里面的特性0 非0 for (var x = 0; x < nodess.length; x++) { if (num == 1) { nodess[x].checked = 1; }else if (num == 2) { nodess[x].checked = !nodess[x].checked; }else if (num == 3) { nodess[x].checked = false; } }*/ for(var x=0;x<nodess.length;x++){ if(num<2){ nodess[x].checked=num; //让全选的复选框可以 单独写个函数 var all=document.getElementsByName("allItem"); for(var y=0;y<all.length;y++){ if(num==1){ all[y].checked=num; }else{ all[y].checked=num; } } }else{ nodess[x].checked=!nodess[x].checked; var all=document.getElementsByName("allItem"); for (var y = 0; y < all.length; y++) { all[y].checked=0; } } } } function checkBysingle(){//全部入选之后,全选的自动选中 var flag = true; var node = document.getElementsByName("mail"); for (var x = 0; x < node.length; x++) { if (node[x].checked == false) { flag = false; break; } } var all = document.getElementsByName("allItem"); for (var y = 0; y < all.length; y++) { if (flag) { all[y].checked = true; } else { all[y].checked = false; }}} function DelBybtn(){//删除行 var tdnode=document.getElementsByName("mail"); /*for(var x=0;x<tdnode.length;x++){ if(tdnode[x].checked){//对象是 checkbox 我们必须要那父级的父级 《tr》,我们需要移除的就是tr对象 var trnode=tdnode[x].parentNode.parentNode;//tr对象 trnode.parentNode.removeChild(trnode);//table对象移除tr对象 // alert("aa"); //节点容器跟Java当中的集合一样,只要是remove(),长度就会变的。这里,需要进行x的复位 x--; }*/ for(var x=tdnode.length-1;x>=0;x--){ if(tdnode[x].checked){//对象是 checkbox 我们必须要那父级的父级 《tr》,我们需要移除的就是tr对象 var trnode=tdnode[x].parentNode.parentNode;//tr对象 trnode.parentNode.removeChild(trnode);//table对象移除tr对象 } toaddcolor(); addEvent(); } } </script> </head> <body> <table id="tabid"> <tr> <th><input type="checkbox" name="allItem" onclick="allcheck(this)"/> 全选 </th> <th>发件人</th> <th>邮件标题</th> <th>邮件附属信息</th></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>张三</td> <td>国庆祝福</td> <td>邮件附属信息1....</td></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>Jack</td> <td>假期堵车</td> <td>邮件附属信息2....</td></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>Jack</td> <td>假期堵车</td> <td>邮件附属信息3....</td></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>Jack</td> <td>假期堵车</td> <td>邮件附属信息4....</td></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>Jack</td> <td>假期堵车</td> <td>邮件附属信息5....</td></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>Tom</td> <td>一些广告</td> <td>邮件附属信息6....</td></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>Tom</td> <td>一些广告</td> <td>邮件附属信息6....</td></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>Tom</td> <td>一些广告</td> <td>邮件附属信息6....</td></tr> <tr> <td><input type="checkbox" name="mail" onclick="checkBysingle(this)" /> </td> <td>Tom</td> <td>一些广告</td> <td>邮件附属信息6....</td></tr> <tr><td><input type="checkbox" name="allItem" onclick="allcheck(this)">全选</td> <td colspan=3><input type="button" value="全选" name="btn1" onclick="AllBybtn(1)" /> <input type="button" value="反选" name="btn2" onclick="AllBybtn(2)"/> <input type="button" value="取消全选" name="btn3" onclick="AllBybtn(0)"/> <input type="button" value="删除所选项" name="btn4" onclick="DelBybtn()"/> </td> </tr> </table> </body> </html>
I hope this article will be helpful to everyone learning JavaScript programming.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.

JavaScript does not require installation because it is already built into modern browsers. You just need a text editor and a browser to get started. 1) In the browser environment, run it by embedding the HTML file through tags. 2) In the Node.js environment, after downloading and installing Node.js, run the JavaScript file through the command line.

How to send task notifications in Quartz In advance When using the Quartz timer to schedule a task, the execution time of the task is set by the cron expression. Now...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.