美文网首页
js基础2作业10

js基础2作业10

作者: HavenYoung | 来源:发表于2018-08-20 19:40 被阅读0次

    html

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
    
        <body>
            <table border="" cellspacing="" cellpadding="">
                <tr>
                    <th id="head" colspan="10">用for循环打印十行十列表格,表格里面写1-100,并且隔列变色</th>
                </tr>
                <link rel="stylesheet" type="text/css" href="css/question10.css" />
                <script src="js/question10.js"></script>
            </table>
    
        </body>
    
    </html>
    
    

    css

    .even{
        height: 25px;
        width: 100px;
        background-color: beige;
    }
    
    .odd{
        height: 25px;
        width: 100px;
        background-color: gold;
    }
    
    

    js

    var count = 1
    for(var row = 0; row < 10; row++){
        document.write("<tr>")
        for(var column = 0; column < 10; column++){
            if(!(column%2)){
                document.write("<td ")
                document.write("id=")
                document.write(row,column)
                document.write(" class='odd'>")
            }else{
                document.write("<td ")
                document.write("id=")
                document.write(row,column)
                document.write(" class='even'>")
            }
            document.write(count)
            document.write("</td>")
            count++
        }
        document.write("</tr>")
    }
    
    
    

    结果图


    jsHomework10.png

    相关文章

      网友评论

          本文标题:js基础2作业10

          本文链接:https://www.haomeiwen.com/subject/jyxriftx.html