Copy codeThe Code is as follows:
<Html>
<Head>
<Script src = "http://code.jquery.com/jquery-1.11.0.min.js"> </script>
<Script>
// Create an html Element
Function $ c (tagname ){
Return document. createElement (tagname );
}
// Content to be executed after the file is loaded
$ (Document). ready (function (){
// Bind the Click Event of the add row button
$ ("# Addrow"). bind ("click", function (){
// Obtain the table
Var tab = $ ("# tab ");
// Create a tr Element
Var tr = $ c ("tr ");
// Append the tr element to the table
Tab. append (tr );
// Create a td Element
Var td1 = $ c ("td ");
// Content of the td Element
Td1.innerHTML = "insert1 ";
// Append the td element to the newly appended tr
Tr. appendChild (td1 );
Var td2 = $ c ("td ");
Td2.innerHTML = "insert2 ";
Tr. appendChild (td2 );
});
// Bind the Click Event of the Delete row button
$ ("# Deleterow"). bind ("click", function (){
// Obtain the first row of the table
Var tab = $ ("# tab tr: eq (0 )");
// Delete this row
Tab. remove ();
});
});
</Script>
</Head>
<Body>
<Table border = '1' id = "tab">
<Tr>
<Td> 123 </td>
<Td> 456 </td>
</Tr>
</Table>
</Br>
<Button id = "addrow"> Add row </button>
<Button id = "deleterow"> delete a row </button>
</Body>
</Html>