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>