<input id= "txtping"/> <table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 1 "id=" ch "> <tr> & Lt;td> China Beijing </td> </tr> <tr> <td> China Shanghai </td> </tr> </table> <script language= "JavaScript" type= "Text/javascript" > var tabobj = document.getElementById ("ch"); Get the Table object for (var i=0; i<tabobj.rows.length;i++)//Add event to cell {tabobj.rows[i].onclick=function () {Document.getele Mentbyid ("txtping"). Value = This.innertext; Take value tabobj.rows[i].onmouseover=function () {this.style.background= "#0EF";}; Row discoloration Tabobj.rows[i].onmouseout=function () {this.style.background= "";}; tabobj.rows[i].style.cursor= "Pointer"; function sets (obj) {document.getElementById ("Div1"). Style.top = document.getElementById (obj). offsettop + DOCUMENT.G Etelementbyid (obj). offsetheight + "px"; document.getElementById ("Div1"). Style.left = document.getElementById (obj). offsetleft + Document.body.scrollLeft + " PX "; }//javascript Add Table function creattable () {///createelement function to create tbody,tr,td,textnode element//The meaning of the elements is not in this description var tables = Document.createeleme NT ("table"); Tables.setattribute ("id", "Chen"); Tables.setattribute ("Border", "1px"); Tables.setattribute ("width", "300px"); var tbody= document.createelement ("tbody"); var row=document.createelement ("tr"); var cell=document.createelement ("TD"); var textnode=document.createtextnode ("Test"); Because each element is the relationship between node and child node, the AppendChild () function is used to connect the nodes Cell.appendchild (textnode); Row.appendchild (cell); Tbody.appendchild (row); Tables.appendchild (TBODY); document.getElementById ("Div3"). appendchild (tables); Add a method for each cell (var j=0;j< tabobj.rows.length;j++)//Line {for (var h=0;h< tabobj.rows.item (0)) by adding a layer to ID number DIV3. ells.length;h++)//cell {tabobj.rows[j].cells[h].onclick=function () {ch (this);}; }} </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]