2017-08-03 135 views
0

我想讓水平模式中的日曆以日期和日期命名。目前我發現只有選擇返回日期名稱的解決方案。JQuery Datepicker - 顯示日期單元格中的日期名稱

下面是代碼示例:

function datePickerSetup() { 
    //todays date 
    var dateToday = new Date(); 
    var todayDate = dateToday.toLocaleDateString("en-GB"); //returns 05-12-2014 
    var todayDateNumber = dateToday.getDate(); //returns 5 if 05-12-2014 
    $('#datepicker-date-selected').text(todayDateNumber); 

    var weekday = new Array(7); 
    weekday[0]= "Sunday"; 
    weekday[1] = "Monday"; 
    weekday[2] = "Tuesday"; 
    weekday[3] = "Wednesday"; 
    weekday[4] = "Thursday"; 
    weekday[5] = "Friday"; 
    weekday[6] = "Saturday"; 

    var todaysDay = weekday[dateToday.getDay()]; // returns Tuesday 
    $('#datepicker-day-of-week').text(todaysDay); 

    $("#datepicker").datepicker({ 
     inline: true, 
     minDate: new Date(), 
     firstDay: 1, 
     dateFormat: "dd-mm-yy", 
     onSelect: function(date) { 
      // work out selected date 
      var dateSelect = $(this).datepicker('getDate'); //used below 

      var dayOfWeek = $.datepicker.formatDate('DD', dateSelect); //shows Monday 
      $('#datepicker-day-of-week').text(dayOfWeek); 

      var dateOfSelected = $.datepicker.formatDate('d', dateSelect); //shows 10 if 10/03/1994 
      $('#datepicker-date-selected').text(dateOfSelected); 
     } 
    }); 
} 

datePickerSetup(); 

下面是類似的問題:JQuery Datepicker - show day of week name in date cell

回答

1

試試這個代碼

使用dayNamesMin選項

$("#datepicker").datepicker({ 
    dayNamesMin: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], 
    beforeShowDay: function (date) { 
    var list=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; 
    var day = date.getDay(); 
    var curr=list[day]; 
    return [true, "",""+curr+""]; 
    } 
}); 

也是用C添加此SS改變日曆

.ui-datepicker { 
    width:auto; 
} 

DEMO

+0

這是工作的寬度。謝謝。 – Foxsk8

+0

很高興幫助你:) – Amal