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.
 
 
 
 

91 lines
2.2 KiB

  1. function addmouth(dom,year,month){
  2. !dom.hasClass("amonth")&&dom.addClass("amonth");
  3. var date = new Date(year,month);
  4. var tomonth = new Date().getMonth();
  5. var today = new Date().getDate();
  6. var dayhtml = [];
  7. var week = ["日","一","二","三","四","五","六"];
  8. dayhtml.push('<div class="showdate"><span class="monthleft">&lt;</span><span class="currentdate">'+date.getFullYear()+'年'+(date.getMonth()+1)+'</span><span>月</span><span class="monthright">&gt;</span></div>')
  9. $.each(week,function(i,v){
  10. dayhtml.push('<div class="aweek">'+week[i]+'</div>')
  11. });
  12. var nextdate = new Date(year, month)
  13. var firstweek = nextdate.getDay();
  14. //var firstweek = date.getDay();
  15. console.log(date)
  16. var first = date.getDate();
  17. var allday = new Date(parseInt(year),(parseInt(month)+1),0).getDate();
  18. //console.log(allday)
  19. //console.log(parseInt(year)+","+(parseInt(month)+1))
  20. // console.log(new Date(year,month+1,0))
  21. for(var i = 0;i<firstweek;i++){
  22. dayhtml.push('<div class="aday"></div>')
  23. };
  24. if (month==tomonth){
  25. for(i=1;i<=allday;i++){
  26. if(i==today){
  27. dayhtml.push('<div class="aday canday">今天</div>')
  28. }
  29. else if(i<today){
  30. dayhtml.push('<div class="aday disday">'+i+'</div>')
  31. }else{
  32. dayhtml.push('<div class="aday canday">'+i+'</div>')
  33. }
  34. }
  35. }else if(month<tomonth){
  36. for(i=1;i<=allday;i++){
  37. dayhtml.push('<div class="aday disday">'+i+'</div>')
  38. }
  39. }else{
  40. for(i=1;i<=allday;i++){
  41. dayhtml.push('<div class="aday canday">'+i+'</div>')
  42. }
  43. }
  44. dom.html(dayhtml.join(""))
  45. $(".canday").on("click",function(){
  46. $(".canday").removeClass('placesel');
  47. $(".canday").removeClass('thisday');
  48. // $(this).next().addClass("placesel");
  49. $(this).addClass("thisday");
  50. })
  51. $(".monthleft").unbind();
  52. $(".monthright").unbind();
  53. $(".monthleft").on("click",function(){
  54. var currentdate = $(".currentdate").html();
  55. currentdate = currentdate.split("年");
  56. addmouth($(".month"),currentdate[0],(currentdate[1]-2));
  57. $(".cartime").removeClass("sel")
  58. selectDate();
  59. })
  60. $(".monthright").on("click",function(){
  61. var currentdate = $(".currentdate").html();
  62. currentdate = currentdate.split("年");
  63. addmouth($(".month"),currentdate[0],(currentdate[1]));
  64. $(".cartime li").removeClass("sel")
  65. selectDate();
  66. })
  67. }