This article shares a simple method of operating js tables for your reference. The specific content is as follows
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>zzzz</title> <style> *{ margin: 0; padding: 0; } body{ width: 1000px; margin: 100px auto; font-family: "Microsoft Yahei"; font-size: 18px; background-color: #fff; } #table tr{ text-align: center; } tbody tr:nth-child(2n+1){ background-color: #ccc; } tbody tr:hover{ background-color: green; } input[type=text]{ height: 25px; width: 136px; background-color: turquoise; margin-bottom: 10px; } </style> <script type="text/javascript"> window.onload=function(){ var otb=document.getElementById("table"); var otr=otb.tBodies[0].rows; var oadd=document.getElementById("add"); var oneme=document.getElementById('name'); var osex=document.getElementById('sex'); var id=otr.length+1; oadd.onclick=function(){ var attr=document.createElement('tr'); var atd1=document.createElement('td'); var atd2=document.createElement('td'); var atd3=document.createElement("td"); var atd4=document.createElement("td"); atd4.innerHTML='<a>Delete</a>'; atd1.innerHTML=id++; atd2.innerHTML=oname.value; atd3.innerHTML=osex.value; atr.appendChild(atd1); atr.appendChild(atd2); atr.appendChild(atd3); atr.appendChild(atd4) otb.tBodies[0].appendChild(atr); atd4.getElementsByTagName('a')[0].onclick=function(){ otb.tBodies[0].removeChild(this.parentNode.parentNode) } } var obtn=document.getElementById("btn"); var otxt=document.getElementById("ss"); obtn.onclick=function(){ for(var i=0;i<otb.tBodies[0].rows.length;i++){ var osta=otb.tBodies[0].rows[i].cells[1].innerHTML.toLowerCase(); var ot=otxt.value.toLowerCase(); var oar=ot.split(' '); otb.tBodies[0].rows[i].style.background=''; for(var j=0;j<oar.length;j++){ if(osta.search(oar[j])!=-1){ otb.tBodies[0].rows[i].style.background='red'; } } } } } } } } </script> </head> <body> <input type="text" placeholder="Please enter search content" id="ss"/> <input type="button" value="Query" id="btn"/><br /> Name: <input type="text" id="name" /> Gender: <input type="text" id="sex" /> <input type="button" value="Add" id="add"/> <table id="table"> <ttrun> <td>Serial number</td> <td>People name</td> <td>Gender</td> <td>Modify</td> </tr> <tbody> <tr> <td>1</td> <td>Zhang San</td> <td>Male</td> <td>Delete</td> </tr> <tr> <td>2</td> <td>Li Si</td> <td>Male</td> <td>Delete</td> </tr> <td>Delete</td> </tr> <td>3</td> <td>Caesar</td> <td>Female</td> <td>Delete</td> </tr> <td>4</td> <td>Liu Yan</td> <td>Female</td> <td>Delete</td> </tr> </tbody> </head> </table> </body></html>The above is all about this article, I hope it will be helpful to everyone's learning.