javascript 手写OOP简易年历

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .container {
            width: 220px;
            border: 20px lightgreen solid;
            margin: 20px auto;
        }
        ul {
            margin: 0;
            padding: 0;
            width: 220px;
            text-align: center;
            background-color: grey;
        }
        li {
            list-style-type: none;
            display: inline-block;
            width: 60px;
            height: 60px;
            margin: 3px;
            padding: 0;
            border: 0;
            background-color: #ffffff;
        }
        .active {
            background-color: red;
        }
        .container div {
            background-color: gray;
            height: 100px;
        }
    </style>
    <script type="text/javascript">

        function DateGuo(oDiv){
            this.aLi = oDiv.getElementsByTagName('li');
            this.oDivIn = oDiv.getElementsByTagName('div')[0];
            this.aGuoH1 = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];
            this.aGuoP = [
                '一月的靖哥哥',
                '二月的靖哥哥',
                '三月的靖哥哥',
                '四月的靖哥哥',
                '五月的靖哥哥',
                '六月的靖哥哥',
                '七月的靖哥哥',
                '八月的靖哥哥',
                '九月的靖哥哥',
                '十月的靖哥哥',
                '十一月的靖哥哥',
                '十一月的靖哥哥'
            ];
            this.setClick();
        }
        DateGuo.prototype.setClick = function(){
            var _this = this;
            for(var i=0;i<this.aLi.length;i++) {
                this.aLi[i].index = i;
                this.aLi[i].onmouseover = function () {
                    this.className = 'active';
                    _this.oDivIn.innerHTML = "<h1>"+_this.aGuoH1[this.index]+"</h1><p>"+_this.aGuoP[this.index]+"</p>";
                };
                this.aLi[i].onmouseout =function(){
                    this.className = '';
                };
            }
        };
        window.onload = function(){
            var oDiv = document.getElementsByClassName('container')[0];
            var oDateGuo = new DateGuo(oDiv);
        };
    </script>
</head>
<body>
<div class="container">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>61</li>
        <li>7</li>
        <li>8</li>
        <li>9</li>
        <li>10</li>
        <li>11</li>
        <li>12</li>
    </ul>
    <div>
        <h2>hello</h2>
        <p>my lady</p>
    </div>
</div>
</body>
</html>

 

posted @ 2017-11-02 13:39  我将枕中记忆抹去任岁月浮光掠影  阅读(185)  评论(0编辑  收藏  举报