动态创建表格
2015-08-07 15:12
513 查看
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>8.6第二题</title> </head> <body> <h3>动态创建table</h3> <table> <tr> <td>行:</td> <td><input id="row"></td> </tr> <tr> <td>列:</td> <td><input id="col"></td> </tr> <tr> <td>边框粗细:</td> <td><input id="borderWidth"></td> </tr> <tr> <td>边框颜色:</td> <td><input id="borderColor"></td> </tr> <tr> <td colspan="2"><button onclick="create()">创建</button></td> </tr> </table> <script> function create(){ var row=document.getElementById("row").value; var col=document.getElementById("col").value; var Width=document.getElementById("borderWidth").value; var Color=document.getElementById("borderColor").value; if(!row || !col || !Width || !Color){ alert("输入不完整!"); }else if(isNaN(row) || isNaN(col) || parseInt(row)!=row || parseInt(col)!=col || row<=0 || col<=0){ alert("行列数必须是正整数!") }else{ var newTable=document.getElementById("newTable"); if(newTable){document.body.removeChild(newTable);} var table=document.createElement("table"); document.body.appendChild(table); table.id="newTable"; for(var i=1;i<=row;i++){ var tr=document.createElement("tr"); table.appendChild(tr); for(var j=1;j<=col;j++){ var td=document.createElement("td") tr.appendChild(td); td.style.border =Width +" solid "+ Color; td.innerHTML=" "; } } } } </script> </body> </html>
View Code
相关文章推荐
- falsh 遮住div 解决方案
- [ExtJS5学习笔记]第第二十四次 Extjs5形式上gridpanel或表单数据后台传输remoteFilter设定
- 解决啃爹的使用 xib Autolaout后8.0以下系统无法滑动scrollView
- 参数估计:最大似然、贝叶斯与最大后验
- tiff格式图片
- jQuery日常使用2
- ExecuteScalar、ExecuteReader不只是我想的这样的用处。
- jQuery常规选择器
- 【JavaScript】——初识
- 在安装Ubuntu时,我们应当如何分区
- windows驱动开发技术详解 VC6与DDK搭配使用的设置
- gcc 源码分析-前端篇1
- shell基础命令
- leetcode面试准备:Lowest Common Ancestor of a Binary Search Tree & Binary Tree
- HDU 3683 Gomoku 模拟 胜局判断
- 常量指针 和 指针常量
- ARM Linux系统的时钟机制
- 小P寻宝记——粗心的基友 SDUT 2825
- ESD静电问题终极解决方案
- mysql 数据表读锁机制详解