|
-
- //当前时间
- var tmonth = new Date();
-
- var year = tmonth.getFullYear();
-
- var month = tmonth.getMonth();
-
- var dom = $('.month');
- //中间变量 记录
- var tttmonth = '';
-
- var tyear = '';
-
-
- window.onload = function(){
- !dom.hasClass("amonth")&&dom.addClass("amonth");
- //当前日期
- var date1 = new Date(year,month);
- //当前月份
- var tomonth = new Date().getMonth();
- //
- var today = new Date().getDate();
- var dayhtml = [];
- var week = ["日","一","二","三","四","五","六"];
- for (var t=1;t<=3;t++){
- dayhtml.push('<div style="clear:both">');
-
- var date = date1;
- month = date.getMonth()+t-1;
-
- console.log(month);
- if (month>=11) {
- tyear = year+1;
- tttmonth = month-12 ;
-
- // month = 0;
- }else{
- tyear =year;
- tttmonth = month;
- }
- if(tttmonth==-1){
- tttmonth=11;
- tyear = year;
- }
- dayhtml.push('<div class="month_title"><span class="current_month">'+(tttmonth+1)+'月'+'</span><span class="current_year">'+tyear+'</span></div>')
-
- // dayhtml.push();
- // $.each(week,function(i,v){
- // dayhtml.push('<div class="aweek" style="float:left">'+week[i]+'</div>')
- // });
-
- var str = '';
-
- $.each(week,function(i,v){
- str += '<div class="aweek ub-f1 text_middle ui_p_t15 ui_p_b15">'+week[i]+'</div>';
- });
- dayhtml.push('<div class="ub" style="margin-left:0.2rem;margin-right:0.2rem;">'+str+'</div>')
-
- var nextdate = new Date(year,month)
- var firstweek = nextdate.getDay();
- // var firstweek = month.getDay();
- // var first = month.getDay();
-
- var allday = new Date(parseInt(year),(parseInt(month)+1),0).getDate();
-
- var daystr = '<div style="margin-left:0.2rem;margin-right:0.2rem;">';
-
- for(var i = 0;i<firstweek;i++){
- daystr+='<div class="aday"></div>'
- };
-
- if (month==tomonth){
- for(i=1;i<=allday;i++){
- if(i==today){
- daystr+='<div class="aday canday today">今天</div>'
- }
- else if(i<today){
- daystr+='<div class="aday disday">'+i+'</div>'
- }else{
- daystr+='<div class="aday canday">'+i+'</div>'
- }
-
- }
- }else if(month<tomonth){
- for(i=1;i<=allday;i++){
- daystr+='<div class="aday disday">'+i+'</div>'
- }
- }else{
- for(i=1;i<=allday;i++){
- daystr+='<div class="aday canday">'+i+'</div>'
- }
- }
-
- daystr += "</div>";
-
-
-
- dayhtml.push(daystr);
- dayhtml.push('</div>');
- }
- dom.html(dayhtml.join(""))
-
- $(".canday").on("click",function(){
- $(".canday").removeClass('select_day');
- $(this).addClass('select_day');
- // $(".canday").removeClass('thisday');
- // $(this).next().addClass("placesel");
- // $(this).addClass("thisday");
- })
-
- }
|