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 = [ '天气很好呀,要开心', '没有下雨,要开心', '每天要开心', '天气很好呀,要开心', '没有下雨,要开心', '每天要开心', '天气很好呀,要开心', '没有下雨,要开心', '每天要开心', '天气很好呀,要开心', '没有下雨,要开心', '每天要开心', ] var oTable = document.getElementById('table'); var oLi = oTable.getElementsByTagName('li'); var op1 = document.getElementById('p1'); 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=''; } this.className='active'; op1.innerHTML='<h2>'+(this.index+1)+'月</h2><p>'+oText[this.index] +'</p>'; } } } </script> <body> <p id='table'> <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='p1'> <h2>一月</h2> <p>稻花香提醒您,七月值得关注的日子</p> </p> </body></html>
Related recommendations:
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!