• js实现表格的随机生成


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Document</title>
    </head>
    <style>
        input{
            height: 30px;
             80px;
            border: 2px solid #ccc;
        }
        .btn{
            color: #fff;
            background: #000;
            border-radius: 6px;
            border: 0;
        }
        .tabstyle{
            border: 1px solid #000;
        }
        .tdstyle{
            border: 1px solid #000;
            height: 30px;
             50px;
            line-height: 30px;
            text-align: center;
        }
    </style>
    <body>
        <div class="getinput" id="getinput">
            行数<input type="text" />
            列数<input type="text" />
            <input type="button" value="生成表格" class="btn"/>
        </div>
        <div class="box" id="box">

        </div>

    </body>
        <script>
            //获取元素
            var getinput=document.getElementById("getinput");
            var getTag=getinput.getElementsByTagName("input");
            var box=document.getElementById("box");
            //点击事件的实现
            getTag[2].onclick=function(){
                //获取用户输入的行数和列数
                var rowCound=parseInt(getTag[0].value);
                var colCound=parseInt(getTag[1].value);
                //创建表格节点
                var createTab=document.createElement("table");
                createTab.className="tabstyle";
                box.appendChild(createTab);

                for(var i=0;i<rowCound;i++){
                    //创建行节点
                    var createTr=document.createElement("tr");
                    createTab.appendChild(createTr);
                    for(var j=0;j<colCound;j++){
                        //创建列节点
                        var createTd=document.createElement("td");
                        createTd.className="tdstyle";
                        //随机生成每个表格中的内容
                        var ranNum=parseInt(Math.random()*15);
                        createTd.innerHTML=ranNum;
                        //随机生成表格的背景颜色
                        rg=parseInt(Math.random()*255);
                        gg=parseInt(Math.random()*255);
                        bg=parseInt(Math.random()*255);
                        createTd.style.background="rgb("+rg+","+gg+","+bg+")";
                        createTr.appendChild(createTd);
                    }
                }
            }
        </script>
    </html>

  • 相关阅读:
    使用npm安装一些包失败了的看过来(npm国内镜像介绍)
    利用JMX统计远程JAVA进程的CPU和Memory
    Spring Boot学习笔记
    django数据库时间存储格式问题
    解决 Ubuntu 无法调节屏幕亮度的问题(转)
    django models auto_now和auto_now_add的区别
    django redis操作
    接口测试的工具
    django中migration文件是干啥的
    mysql简单操作(实时更新)
  • 原文地址:https://www.cnblogs.com/html-go/p/5823627.html
Copyright © 2020-2023  润新知