Preface At work, I need to count the materials submitted by employees every week, but I don’t want to copy and paste them one by one, so I have to write a small tool to help me find who has not submitted the materials. Let’s fix the page first <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> textarea { /* border: none; */ width: 49%; height: 400px; /* font-size: 17pt; */ } #btn { width: 100%; height: 50px; position: relative; top: 0px; /* position: absolute; */ } #p2 { margin-left: 940px; margin-top: -38px; } </style> </head> <body> <button id="btn" class="ambi-light-button">Compare</button> <textarea id="txt" type="text" placeholder="Should be submitted"></textarea> <textarea id="txt2" type="text" placeholder="Submitted"></textarea> <hr> <p>Not submitted</p> <p id="p2">List of absent persons has been submitted</p> <textarea id="txt3" type="text" placeholder="Not submitted"></textarea> <textarea id="txt4" type="text" placeholder="Submitted list of people not on the list"></textarea> </body> </html> A bit ugly, but it doesn't matter if you use it yourself Start writing JS code <script //First get the input box and button let txt = document.querySelector('#txt') let txt2 = document.querySelector('#txt2') let txt3 = document.querySelector('#txt3') let txt4 = document.querySelector('#txt4') let btn = document.querySelector('#btn') //Then write an array to find the difference const getDifference = function (a, b) { //Explanation: If the two functions passed in are arrays if (a.constructor === Array && b.constructor === Array) { let set1 = new Set(a); let set2 = new Set(b); // Use Set to remove duplicates and filter to find the difference return Array.from(new Set([...set1].filter(x => !set2.has(x)))); } return null; } // Simply give the button a click event btn.onclick = function () { //List of people who should submit let Should_sub = txt.value.split('\n') //List of people who have not submitted yet let already_sub = txt2.value.split('\n') let l3 = getDifference(Should_sub, already_sub) //Number of people not submitted in the list let l4 = getDifference(already_sub, Should_sub) //The filtered values are fed back to the two input boxes on the page txt3.value = l3.join('\n') txt4.value = l4.join('\n') } </script> Summarize This is the end of this article about using JavaScript difference to implement a comparison widget. For more relevant JS difference implementation comparison widget content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to use Nginx to proxy multiple application sites in Docker
>>: MySQL 5.7.23 decompression version installation tutorial with pictures and text
Table of contents Method 1 Method 2 After install...
Rendering After looking up relevant information o...
1. Top-level usage 1. Install cnpm npm i -g cnpm ...
Table of contents 1. Introduction: 2. The first i...
In Node.js, a .js file is a complete scope (modul...
Recently, a friend asked me a question: When layo...
Preface I recently encountered a problem at work....
Often when building a SPA, you will need to prote...
Mysql slow query explanation The MySQL slow query...
When laying out the page, in order to give users ...
Grid is a two-dimensional grid layout system. Wit...
Now most of the Docker images are based on Debian...
1. Slow query due to lack of index or invalid ind...
1. Apache static resource cross-domain access Fin...
Introduction The meta tag is an auxiliary tag in ...