Effect:
Code:
Copy codeThe Code is as follows:
<Head runat = "server">
<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>
</Head>
<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 information"/>
</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>
Alliance
</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
</Td>
<Td>
UD
</Td>
<Td>
Representative hero: DK
</Td>
<Td>
</Td>
</Tr>
<Tr>
<Td>
4
</Td>
<Td>
Night genie
</Td>
<Td>
NE
</Td>
<Td>
Representative hero: DH
</Td>
<Td>
</Td>
</Tr>
</Tbody>
</Table>
</Body>