<ptml xmlns= "http://www.w3.org/1999/xhtml" > <pead> <meta http-equiv= "Content-type" content= "text/" html charset=gb2312 "/> <title>javascript operation table features </title> <script type=" Text/javascript "><!-- function f () {//Create a table var otable = document.createelement ("table"); Otable.setattribute ("Border", "1"); Otable.setattribute ("width", "300px"); var otbody = document.createelement ("tbody"); Otable.appendchild (Otbody); Create the first row of Otbody.insertrow (0); Otbody.rows[0].insertcell (0); Otbody.rows[0].cells[0].appendchild (document.createTextNode ("Cell 1,1")); Otbody.rows[0].insertcell (1); Otbody.rows[0].cells[1].appendchild (document.createTextNode ("Cell 2,1")); Create a second row of otbody.insertrow (1); Otbody.rows[1].insertcell (0); Otbody.rows[1].cells[0].appendchild (document.createTextNode ("Cell 1,2")); Otbody.rows[1].insertcell (1); Otbody.rows[1].cells[1].appendchild (document.createTextNode ("Cell 2,2")); Jb51.net Document.body.appendChild (otable);}//--></script> </pead> <body onclick= "f ();" > <div>hello</div> <table border= "1" width= "300px" > <tbody> <tr> <td>cell 1,1& lt;/td> <td>cell 2,1</td> </tr> <tr> <td>cell 1,2</td> <td>cell 2,2</ td> </tr> </tbody> </table> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
You can see the effect directly by clicking on any part of the page.