JavaScript introduction

JavaScript It's a lightweight , Interpretive Web development language , The language system is not very complicated , Easy to learn . Because all modern browsers are embedded JavaScript engine ,JavaScript The source code can be interpreted and executed directly in the browser , Users don't have to worry about support , This is a problem js How to get started

The addition and deletion of form information

ordinary DOM operation html Tag , The code is as follows :
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document
</title> <style type="text/css"> *{ margin: 0; padding: 0; } </style> <script
type="text/javascript"> function delA(){ // Click on the hyperlink to delete the line // use this, Delete parent element var tr =
this.parentNode.parentNode; // Gets the name of the person to be deleted var name=tr.getElementsByTagName("td")[
0].innerHTML; // Prompt user to delete var flag=confirm(" Delete "+name+"?"); if(flag){ tr.
parentNode.removeChild(tr); } // Prevent browser default behavior , For example, pop up a new tab return false; } window.
onload=function(){ // Click the hyperlink to delete an employee's information // Get a link var allA=document.getElementsByTagName
("a"); // Binding response function for(var i=0;i<allA.length;i++){ allA[i].onclick=delA; }
// Add employee function , Click the button to add the information to the form var addEmpButton = document.getElementById("addEmpButton"
); addEmpButton.onclick=function(){ // Gets the text content in the input box var empName=document.
getElementById("empName").value; var email=document.getElementById("email").
value; var salary=document.getElementById("salary").value; // Create a tr var tr=
document.createElement("tr"); // towards tr Add content to tr.innerHTML="<td>"+empName+"</td>"+
"<td>"+email+"</td>"+ "<td>"+salary+"</td>"+ "<td><a
href='javascript:;'>Delete</a></td>"; var a= tr.getElementsByTagName("a")[0]; a.
onclick=delA; // hold tr Put in table in var employeeTable=document.getElementById(
"employeeTable"); // obtain tbody var tbody=document.getElementsByTagName("tbody")[0];
tbody.appendChild(tr); } } </script> </head> <body> <table id="employeeTable">
<tr> <th>Name</th> <th>Email</th> <th>Salary</th> <th> </th> </tr> <tr> <td
>Tom</td> <td>tom@tom.com</td> <td>5000</td> <td><a href="">Delete</a></td> </tr
> <tr> <td>Jerry</td> <td>jerry@sohu.com</td> <td>8000</td> <td><a href="">
Delete</a></td> </tr> <tr> <td>Bob</td> <td>bob@tom.com</td> <td>10000</td> <td>
<a href="">Delete</a></td> </tr> <div id="formDiv"> <h4> Add new employee </h4> <table> <tr>
<td class="word">name: </td> <td class="inp"> <input type="text" name="empName"
id="empName"> </td> </tr> <tr> <td class="word">email: </td> <td class="inp"> <
input type="text" name="email" id="email"> </td> </tr> <tr> <td class="word">
salary:</td> <td class="inp"> <input type="text" name="salary" id="salary"> </td
> </tr> <tr> <td colspan="2" align="center">
<!--colspan and rowspan Properties are the number of rows and columns a cell can span --> <!--align Property is the text alignment position --> <button id="
addEmpButton" value="abc"> Submit </button> </td> </tr> </table> </div> </table>
</body> </html>
The comments in the code snippet are very clear , Suitable for hand training .

Technology
©2020 ioDraw All rights reserved
Swing actual combat Understanding closure about vue in el-date-picker type=daterange The problem of date not echoing Ubuntu 18.04 swap Partition expansion Snake code --c Language Edition visual c++6.0 open 【Golang Basic series 10 】Go language On conditional sentences ifString class —— summary ,String The nature of , Memory resolution , Commonly used APIAdobe Illustrator Publish native support Apple Silicon Test version of the software study java My first class antd table sort