的Html日历不着陆一个月

问题描述:

返回的日期值仍试图获得的jQuery举行。不是很擅长。的Html日历不着陆一个月

我有一个HTML日历的问题。此日历上的一切工作,除了加载日历第一次完美的“着陆一个月占领日期不返回值。”

如果负载后,我选择其他的几个月里,我可以看到日期占据,甚至重新选择的着陆一个月(第一个DropDownList)后日期可以有,但只是无法看到第一次加载。

下面是代码:

var cal = new Calendar(); 

    var unavailable_days_month_1 = [1,2,3]; 
    var unavailable_days_month_2 = [4,5,6]; 
    var unavailable_days_month_3 = [7,8,9]; 
    var unavailable_days_month_4 = [10,11,12]; 
    var unavailable_days_month_5 = [13,14,15]; 
    var unavailable_days_month_6 = [16,17,18]; 
    var unavailable_days_month_7 = [19,20,21]; 
    var unavailable_days_month_8 = [22,23,24]; 
    var unavailable_days_month_9 = [25,26,27]; 
    var unavailable_days_month_10 = [28,29,30]; 
    var unavailable_days_month_11 = [2,4,31]; 
    var unavailable_days_month_12 = [7,9,11]; 

    var current_date = new Date(); 
    var current_month = (current_date.getMonth() + 1); 
    var current_year_month = (1900 + current_date.getYear()) + "-" + current_month; 
    tjq("#select-month").find("[value='" + current_year_month + "']").prop("selected", "selected"); 
    /* My problem starts from here. How can I return the dates value for landing calender month */ 
    cal.generateHTML(current_date.getMonth(), (1900 + current_date.getYear()), "unavailable_days_month_" + current_month); 
    tjq(".calendar").html(cal.getHTML()); 

    tjq("#select-month").change(function() { 
     var selected_year_month = tjq("#select-month option:selected").val(); 
     var year = parseInt(selected_year_month.split("-")[0], 10); 
     var month = parseInt(selected_year_month.split("-")[1], 10); 
     cal.generateHTML(month - 1, year, getUnavailDays(month)); 
     tjq(".calendar").html(cal.getHTML()); 
    }); 

     function getUnavailDays(month){ 
      if (month === 1) return unavailable_days_month_1; 
      if (month === 1) return unavailable_days_month_1; 
      if (month === 2) return unavailable_days_month_2; 
      if (month === 3) return unavailable_days_month_3; 
      if (month === 4) return unavailable_days_month_4; 
      if (month === 5) return unavailable_days_month_5; 
      if (month === 6) return unavailable_days_month_6; 
      if (month === 7) return unavailable_days_month_7; 
      if (month === 8) return unavailable_days_month_8; 
      if (month === 9) return unavailable_days_month_9; 
      if (month === 10) return unavailable_days_month_10; 
      if (month === 11) return unavailable_days_month_11; 
      if (month === 12) return unavailable_days_month_12; 

      return; 
     } 

任何建议,将不胜感激。 在此先感谢。

+1

你应该重构你的代码开始。考虑创建一个名为unavailable_days_month其中索引是月份的数组。 – Owen

我不得不做这些改变:

var current_date = new Date(); 
var current_month = (current_date.getMonth() + 1); 
var current_year_month = (1900 + current_date.getYear()) + "-" + (current_date.getMonth() + 1); 
tjq("#select-month").find("[value='" + current_year_month + "']").prop("selected", "selected"); 
cal.generateHTML(current_date.getMonth(), (1900 + current_date.getYear()), getCurrMonth(current_month)); 
tjq(".calendar").html(cal.getHTML()); 

function getCurrMonth(current_month){ 
    if (current_month === 1) return unavailable_days_month_1; 
    if (current_month === 2) return unavailable_days_month_2; 
    if (current_month === 3) return unavailable_days_month_3; 
    if (current_month === 4) return unavailable_days_month_4; 
    if (current_month === 5) return unavailable_days_month_5; 
    if (current_month === 6) return unavailable_days_month_6; 
    if (current_month === 7) return unavailable_days_month_7; 
    if (current_month === 8) return unavailable_days_month_8; 
    if (current_month === 9) return unavailable_days_month_9; 
    if (current_month === 10) return unavailable_days_month_10; 
    if (current_month === 11) return unavailable_days_month_11; 
    if (current_month === 12) return unavailable_days_month_12; 

    return; 
}