js基础2作业10

2018-08-20  本文已影响0人  HavenYoung

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
上一篇下一篇

猜你喜欢

热点阅读