我可以突出显示特定的日期吗-像datepicker js中的所有星期一星期二等 [英] can i Highlight specific days - like all mondays tuesdays etc in datepicker js

查看:57
本文介绍了我可以突出显示特定的日期吗-像datepicker js中的所有星期一星期二等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想突出显示日期选择器中的日期.我正在使用下面的代码突出显示它们.但要突出显示日期选择器的所有日子.

I am trying to highlight days in datepicker. I am using the folowwing code to highlight them.BUt this highlights all the days of the datepicker.

  dates.data = ['0','1','2'] // days of week
 beforeShowDay: function (date) {   
     if($.inArray(date.getDay(), dates.data)) {
          // if it is return the following.
              return [true, 'ui-state-error', 'tooltip text'];
              } else {
                             // default
               return [true, '', ''];
              }
}

推荐答案

 var highlight_dates = {};
    highlight_dates[ new Date( '03/10/2020' )] = new Date( '03/10/2020' );
    highlight_dates[ new Date( '02/21/2020' )] = new Date( '02/21/2020' );
    
    $('#datepicker').datepicker({
       beforeShowDay: function(date) {
          var highlight = highlight_dates[date];
            if( highlight ) {
                 return [true, "class-to-highlight", 'Special Event'];
            } else {
                 return [true, '', ''];
            }
       }
    });

 .class-to-highlight{
           background-color: #ff0;
       }

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<p>Date: <input type="text" id="datepicker"></p>

这篇关于我可以突出显示特定的日期吗-像datepicker js中的所有星期一星期二等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆