Home > Web Front-end > JS Tutorial > body text

Implementation of simple calendar in js innerHtml

小云云
Release: 2018-03-12 16:42:36
Original
1391 people have browsed it

This article mainly shares with you the implementation of a simple calendar in innerHtml in js. The idea is similar to that of tabs. I hope it can help everyone.

1. To change the bottom text, you can use an array, put their contents into an array, and then use string splicing to achieve
2. innerHtml is used Set the text in the label, and value is used to set the text value in the input
3. For string connection, in order to prevent numbers and letters from being connected together, you can use brackets. That is, the priority of addition in mathematics is the same

<!DOCTYPE html><html>
    <head>
        <meta charset="UTF-8">
        <title>简易日历</title>
    </head>
    <style>
        #table ul{width: 200px;height:220px ;}
        #table li{float: left;width:50px;height:50px ;border: 1px solid blue;margin-right: 5px;        list-style-type: none;text-align: center;margin-top: 5px;}
        #table .active{background-color: #0000FF;cursor: pointer;}
        #p1{width: 200px;height:150px;border:1px solid forestgreen ;text-align: center;margin-left: 20px;}
    </style>
    <script>
        window.onload=function(){
            var oText = [            &#39;天气很好呀,要开心&#39;,            &#39;没有下雨,要开心&#39;,            &#39;每天要开心&#39;,            &#39;天气很好呀,要开心&#39;,            &#39;没有下雨,要开心&#39;,            &#39;每天要开心&#39;,            &#39;天气很好呀,要开心&#39;,            &#39;没有下雨,要开心&#39;,            &#39;每天要开心&#39;,            &#39;天气很好呀,要开心&#39;,            &#39;没有下雨,要开心&#39;,            &#39;每天要开心&#39;,
            ]            var oTable = document.getElementById(&#39;table&#39;);            var oLi = oTable.getElementsByTagName(&#39;li&#39;);            var op1 = document.getElementById(&#39;p1&#39;);            for(var i=0;i<oLi.length;i++){
                oLi[i].index = i;
                oLi[i].onmousemove=function(){
                    for(var i=0;i<oLi.length;i++){
                        oLi[i].className=&#39;&#39;;
                    }                    this.className=&#39;active&#39;;
                    op1.innerHTML=&#39;<h2>&#39;+(this.index+1)+&#39;月</h2><p>&#39;+oText[this.index] +&#39;</p>&#39;;
                }
            }
        }    </script>
    <body>
        <p id=&#39;table&#39;>
            <ul>
                <li class="active"><h2>1</h2></li>
                <li><h2>2</h2></li>
                <li><h2>3</h2></li>
                <li><h2>4</h2></li>
                <li><h2>5</h2></li>
                <li><h2>6</h2></li>
                <li><h2>7</h2></li>
                <li><h2>8</h2></li>
                <li><h2>9</h2></li>
                <li><h2>10</h2></li>
                <li><h2>11</h2></li>
                <li><h2>12</h2></li>
            </ul>
        </p>
        <p id=&#39;p1&#39;>
            <h2>一月</h2>
            <p>稻花香提醒您,七月值得关注的日子</p>
        </p>
    </body></html>
Copy after login

Related recommendations:

js’s simplest native calendar

Share how to implement a calendar

JS implements a simple calendar

The above is the detailed content of Implementation of simple calendar in js innerHtml. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!