You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

112 lines
2.5 KiB

  1. //当前时间
  2. var tmonth = new Date();
  3. var year = tmonth.getFullYear();
  4. var month = tmonth.getMonth();
  5. var dom = $('.month');
  6. //中间变量 记录
  7. var tttmonth = '';
  8. var tyear = '';
  9. window.onload = function(){
  10. !dom.hasClass("amonth")&&dom.addClass("amonth");
  11. //当前日期
  12. var date1 = new Date(year,month);
  13. //当前月份
  14. var tomonth = new Date().getMonth();
  15. //
  16. var today = new Date().getDate();
  17. var dayhtml = [];
  18. var week = ["日","一","二","三","四","五","六"];
  19. for (var t=1;t<=3;t++){
  20. dayhtml.push('<div style="clear:both">');
  21. var date = date1;
  22. month = date.getMonth()+t-1;
  23. console.log(month);
  24. if (month>=11) {
  25. tyear = year+1;
  26. tttmonth = month-12 ;
  27. // month = 0;
  28. }else{
  29. tyear =year;
  30. tttmonth = month;
  31. }
  32. if(tttmonth==-1){
  33. tttmonth=11;
  34. tyear = year;
  35. }
  36. dayhtml.push('<div class="month_title"><span class="current_month">'+(tttmonth+1)+'月'+'</span><span class="current_year">'+tyear+'</span></div>')
  37. // dayhtml.push();
  38. // $.each(week,function(i,v){
  39. // dayhtml.push('<div class="aweek" style="float:left">'+week[i]+'</div>')
  40. // });
  41. var str = '';
  42. $.each(week,function(i,v){
  43. str += '<div class="aweek ub-f1 text_middle ui_p_t15 ui_p_b15">'+week[i]+'</div>';
  44. });
  45. dayhtml.push('<div class="ub" style="margin-left:0.2rem;margin-right:0.2rem;">'+str+'</div>')
  46. var nextdate = new Date(year,month)
  47. var firstweek = nextdate.getDay();
  48. // var firstweek = month.getDay();
  49. // var first = month.getDay();
  50. var allday = new Date(parseInt(year),(parseInt(month)+1),0).getDate();
  51. var daystr = '<div style="margin-left:0.2rem;margin-right:0.2rem;">';
  52. for(var i = 0;i<firstweek;i++){
  53. daystr+='<div class="aday"></div>'
  54. };
  55. if (month==tomonth){
  56. for(i=1;i<=allday;i++){
  57. if(i==today){
  58. daystr+='<div class="aday canday today">今天</div>'
  59. }
  60. else if(i<today){
  61. daystr+='<div class="aday disday">'+i+'</div>'
  62. }else{
  63. daystr+='<div class="aday canday">'+i+'</div>'
  64. }
  65. }
  66. }else if(month<tomonth){
  67. for(i=1;i<=allday;i++){
  68. daystr+='<div class="aday disday">'+i+'</div>'
  69. }
  70. }else{
  71. for(i=1;i<=allday;i++){
  72. daystr+='<div class="aday canday">'+i+'</div>'
  73. }
  74. }
  75. daystr += "</div>";
  76. dayhtml.push(daystr);
  77. dayhtml.push('</div>');
  78. }
  79. dom.html(dayhtml.join(""))
  80. $(".canday").on("click",function(){
  81. $(".canday").removeClass('select_day');
  82. $(this).addClass('select_day');
  83. // $(".canday").removeClass('thisday');
  84. // $(this).next().addClass("placesel");
  85. // $(this).addClass("thisday");
  86. })
  87. }