LoginSignup
1
0

More than 5 years have passed since last update.

jQuery UI Datepicker に休日と休日名のツールチップを表示させる

Last updated at Posted at 2017-10-19

jQuery UI Datepicker に休日(赤色にする)と休日名のツールチップを表示させる

先に結論(こんな感じになります)
https://jsfiddle.net/4h2b29yk/1/

CSS

.saturday a {
  color: blue !important;
}
.holiday a {
  color: red !important;
}

JavaScript

// tooltip and holiday saturday class  
$(function() {
  $("#datepicker").datepicker({
    beforeShowDay: function(date) {
      var holidayName = Holiday.getHolidayName(date);
      if (holidayName){
        return [true, "holiday", holidayName];// 第2引数でクラス追加 第3引数でツールチップ
      }
      if(date.getDay() === 0) {// 日曜日にもholidayクラス
        return [true, "holiday"];
      }
      if(date.getDay() === 6) {// 土曜日にsaturdayクラス
        return [true, "saturday"];
      }
      return [true, ""];
    }
  });
});

休日判定には
https://qiita.com/horikeso/items/16da8bce3fbbee87aa45
を使用しました。

参考
http://api.jqueryui.com/datepicker/#option-beforeShowDay

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0