The addition, deletion, and modification code of
js only has the js code. There is no description. Those with a basic knowledge of js can learn about it.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>表格记录增删改查</title> <style type="javaScript"> tr{ text-align:center; } </style> <script type="text/javascript"> //通过新增按钮来控制表格的显示与隐藏 var optionFlag = "save"; var updateRowIndex = -1; var checkFlag=false;//默认为不显示 function show() { optionFlag = "save"; var f = document.getElementById("did");//获得id为did的 div if(!checkFlag) { f.style.visibility="visible"; }else{ f.style.visibility="hidden"; } checkFlag=!checkFlag; } //通过保存按钮将数据添加到表格中 function insertRow_() { switch(optionFlag) { case "save" : insertRow_$save(); break; case "update" : insertRow_$update(); break; default : alert("操作失败!!"); } function insertRow_$save() { //通过id获得要添加数据的表格 var table = document.getElementById("tableid"); //将所输入的内容赋给定义的变量 var titleName = document.getElementById("title").value; var digestName = document.getElementById("digest").value; var authorName = document.getElementById("author").value; //获取下拉框内的内容 var selectIndex_ = document.getElementById("select"); var option = selectIndex_.options[selectIndex_.selectedIndex]; var selectName = option.text; //获取编号的内容 var numberid = table.rows.length; //在表尾添加一行数据 var row_ = table.insertRow(table.rows.length); row_.insertCell(0).innerHTML = numberid; row_.insertCell(1).innerHTML = titleName; row_.insertCell(2).innerHTML = digestName; row_.insertCell(3).innerHTML = authorName; row_.insertCell(4).innerHTML = selectName; row_.insertCell(5).innerHTML = '<input type="button" value="修改" onclick="update_(this.parentNode.parentNode)"></input> <input type="button" value="删除" onclick="delete_(this.parentNode.parentNode)"></input>'; document.getElementById("title").value = ""; document.getElementById("digest").value = ""; document.getElementById("author").value = ""; document.getElementById("select").options[0].selected="true"; var f = document.getElementById("did"); f.style.visibility="hidden"; alert("insert数据成功!!"); } //修改后的保存 var tr; function insertRow_$update() { var table = document.getElementById("tableid"); tr = table.rows[updateRowIndex]; var p = document.getElementById("title"); tr.cells[1].innerHTML = p.value; p = document.getElementById("digest"); tr.cells[2].innerHTML = p.value; p = document.getElementById("author"); tr.cells[3].innerHTML = p.value; p = document.getElementById("select"); var Index_ = p.selectedIndex; var option = p.options[Index_]; var selectName = option.text; tr.cells[4].innerHTML = selectName; document.getElementById("title").value = ""; document.getElementById("digest").value = ""; document.getElementById("author").value = ""; document.getElementById("select").options[0].selected="true"; var f = document.getElementById("did"); f.style.visibility="hidden"; alert("update数据成功!!"); } } //通过删除按钮 删除当前所在行 function delete_(row_) { var table = document.getElementById("tableid"); table.deleteRow(row_.rowIndex); refurbish_(); alert("delete数据成功!!"); } //刷新 function refurbish_() { var table = document.getElementById("tableid"); //获得table的行数 var rows = table.rows; for(var i=1;i<rows.length;i++) { rows[i].cells[0].innerHTML = i; } } //通修改按钮对table里的数据进行修改 function update_(row) { updateRowIndex = row.rowIndex; optionFlag = "update"; //对table里的数据进行回显 document.getElementById("title").value = row.cells[1].innerHTML; document.getElementById("digest").value = row.cells[2].innerHTML; document.getElementById("author").value = row.cells[3].innerHTML; var selectText = row.cells[4].innerHTML; var sel = document.getElementById("select"); var ops = sel.options; for(var i=0;i<ops.length;i++) { if(selectText==ops[i].text) { sel.options[i].selected = "true"; } } var f = document.getElementById("did"); f.style.visibility="visible"; } </script> </head> <body> <input type="button" value="新增" onclick="show()"></input> <div> <table border = "1" cellspacing = "0" id="tableid" width="90%"> <tr bgcolor="yellow"> <th>编号</th> <th>名称</th> <th>代码</th> <th>机构</th> <th>类别</th> <th>操作</th> </tr> <tr> <td>1</td> <td>民生宝</td> <td>100021</td> <td>ms</td> <td>基金</td> <td> <input type="button" value="修改" onclick="update_(this.parentNode.parentNode)"></input> <input type="button" value="删除" onclick="delete_(this.parentNode.parentNode)"></input> </td> </tr> </table> </div> <br> <div align="center" id="did" style="visibility:hidden"> <form action=""> <table> <tr> <td>标题:</td> <td><input type="text" id="title"></input></td> <td>摘要:</td> <td><input type="text" id="digest"></input></td> </tr> <tr> <td>作者:</td> <td><input type="text" id="author"></input></td> <td>类别:</td> <td align="left"> <select id="select"> <option>证劵</option> <option>基金</option> <option>股票</option> </select> </td> </tr> </table> <br> <center> <input type="button" value="保存" onclick="insertRow_()"></input> <input type="reset" value="重置"></input> </center> </form> </div> </body> </html>
The above is all the code for adding, deleting, checking and modifying js, collect it and study it slowly
Related recommendations:
A brief introduction to foreach and each in JS
Summary of JS page refresh methods
Js parameters Passing and copying variables
Native js method to implement asynchronous file upload
The above is the detailed content of javaScript addition, deletion, modification and query. For more information, please follow other related articles on the PHP Chinese website!

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

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


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools