代码描述:javascript动态创建table表格。javascript动态创建table表格代码下载
在实际编写代码过程中,可能需要动态创建表格。 代码如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <style type="text/css"> #theid{ height:100px; border:1px solid #ccc; border-collapse:collapse; } #theid td{ border:1px solid #ccc; padding:5px; } </style> <script type="text/javascript"> window.onload=function(){ var obt=document.getElementById("bt"); obt.onclick=function(){ var otable=document.createElement("table"); otable.style.width="200px"; otable.style.textAlign="center"; otable.id="theid"; var otr=document.createElement("tr"); var otd=document.createElement("td"); var otext=document.createTextNode("蚂蚁部落") otd.appendChild(otext); otr.appendChild(otd); otr.appendChild(otd.cloneNode()); otable.appendChild(otr); otable.appendChild(otr.cloneNode()); document.body.appendChild(otable); } } </script> </head> <body> <input type="button" id="bt" value="创建表格"/> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能