Home > Web Front-end > JS Tutorial > A perpetual calendar written with jquery (self-written)_jquery

A perpetual calendar written with jquery (self-written)_jquery

WBOY
Release: 2016-05-16 17:03:10
Original
1165 people have browsed it
复制代码 代码如下:






<script> <br>function getTime(year,month,day){ <br>y = year <br>m = month <br>d = day <br>var myDate = new Date(year,month-1,day); <br>return myDate; <br>} <br>function days_in_month(year, month) { <br>y = year; <br>m = month; <br>return 32 - new Date(y, m - 1, 32).getDate(); <br>} <br>function view(year,month){ <br><br>var w = getTime(year,month,1).getDay()-1; <br>var num = days_in_month(year,month); <br>var index = 1; <br>//console.log(w); <br>var data = new Array(); <br>for(var d = 0; d < num w; d ){ <BR>if(d<w){ <BR>data[d] = ''; <BR>}else{ <BR>data[d] = index; <BR>index ; <BR>} <BR>} <BR>$("#content").html(''); <BR>for(var k =0;k < data.length;k ){ <BR>if(k%7==0){ <BR>$("#content").append("<div id='t" k "' class='date1'>" data[k] "</div><br>"); <br>}else{ <br>$("#content").append("<div id='t" k "' class='date1'>" data[k] "</div>"); <br>} <br>} <br>$("#content > div").mouseover(function(){ <br>if($(this).text()!=''){ <br>$(this).css('background','red'); <br>} <br>}); <br>$("#content > div").mouseout(function(){ <br>if($(this).text()!=''){ <br>$(this).css('background','gray'); <br>} <br>}); <br>} <br><br>$(document).ready(function (){ <br>for(var t = 1970; t < 2999; t ){ <BR>$("#yearsel").append("<option value ='" t "'>" t "</option>"); <br>} <br>for(var y = 1; y < 13;y ){ <BR>$("#monthsel").append("<option value ='" y "'>" y "</option>"); <br>} <br>var year = new Date().getFullYear(); <br>var month = new Date().getMonth() 1; <br>var day = new Date().getDate(); <br>var w = getTime(year,month,1).getDay()-1; <br>var num = day w -1; <br>$("#yearsel").change(function(){ <br>year = $("#yearsel option:selected").text(); <br>month = $("#monthsel option:selected").text(); <br>view(year,month); <br>}); <br>$("#monthsel").change(function(){ <br>year = $("#yearsel option:selected").text(); <br>month = $("#monthsel option:selected").text(); <br>view(year,month); <br>}); <br>var oDate = ['星期一','星期二','星期三','星期四','星期五','星期六','星期日',]; <br>for(var i = 0;i < 7;i ){ <BR>$("#title").append("<div class='date'><b>" oDate[i] "</b></div>"); <br>} <br>$("#yearsel option[value='" year "']").attr("selected", true); <br>view(year,month); <br>//标记当前日期 <br>$("#t" num).css('background','yellow'); <br>}); <br></script>



万年历













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