JS Small function (Operation table--Dynamic Add delete form and data) implement code _javascript skill

Source: Internet
Author: User

Effect:

Code:

Copy Code code as follows:

<title></title>
<style type= "Text/css" >
Tr
{
height:30px;
}
</style>
<script type= "Text/javascript" >
Window.onload = function () {
var oname = document.getElementById (' txt1 ');
var oeasyname = document.getElementById (' txt2 ');
var Ohero = document.getElementById (' txt3 ');
var obtn = document.getElementById (' btn ');
var otab = document.getElementById (' tab1 ');
var num = otab.tbodies[0].rows.length + 1;
Obtn.onclick = function () {
var oTr = document.createelement (' tr ');

var oTd = document.createelement (' TD ')
otd.innerhtml = num++;
Otr.appendchild (OTD);

var oTd = document.createelement (' TD ');
otd.innerhtml = Oname.value;
Otr.appendchild (OTD);

var oTd = document.createelement (' TD ');
otd.innerhtml = Oeasyname.value;
Otr.appendchild (OTD);

var oTd = document.createelement (' TD ');
otd.innerhtml = Ohero.value;
Otr.appendchild (OTD);

var oTd = document.createelement (' TD ');
otd.innerhtml = ' <a href= ' # ' > Delete </a> ';
Otr.appendchild (OTD);
Otd.getelementsbytagname (' a ') [0].onclick = function () {
Otab.tbodies[0].removechild (This.parentNode.parentNode);
}
Otab.tbodies[0].appendchild (OTR);
}
};
</script>
<body>
<div style= "margin-left:300px; margin-top:30px; " >
Race Name: <input type= "text" id= "Txt1"/>
Race abbreviation: <input type= "text" id= "Txt2"/>
Hero: <input type= "text" id= "Txt3"/>
<input type= "button" id= "BTN" value= "Add info"/>
</div>
<table id= "Tab1" border= "1" style= "text-align:center; width:800px; margin-left:300px;
margin-top:10px; " >
<thead>
<tr style= "Background-color: #FF0000" >
<td>
Serial number
</td>
<td>
Race name
</td>
<td>
Race abbreviation
</td>
<td>
Hero
</td>
<td>
Operation
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
1
</td>
<td>
Human Union
</td>
<td>
HUM
</td>
<td>
Representative Hero: AM
</td>
<td>
</td>
</tr>
<tr>
<td>
2
</td>
<td>
Orc tribe.
</td>
<td>
ORC
</td>
<td>
Representative Hero: BM
</td>
<td>
</td>
</tr>
<tr>
<td>
3
</td>
<td>
Undead dead
</td>
<td>
Ud
</td>
<td>
Representative Hero: DK
</td>
<td>
</td>
</tr>
<tr>
<td>
4
</td>
<td>
Night Elf
</td>
<td>
NE
</td>
<td>
Representative Hero: DH
</td>
<td>
</td>
</tr>
</tbody>
</table>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.