JavaScript:jQuery Datepicker - 特定日期的简单突出显示,谁能提供帮助?(内有来源) [英] JavaScript: jQuery Datepicker - simple highlighting of specific days, who can help? (source inside)

查看:15
本文介绍了JavaScript:jQuery Datepicker - 特定日期的简单突出显示,谁能提供帮助?(内有来源)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Datepicker 来突出显示特定日期.这是我的最新代码:

i want to use the Datepicker for highlighting specific dates. Here is my latest code:

<script type="text/javascript">

var dates = [30/04/2010, 01/05/2010];

$(function(){

    $('#datepicker').datepicker({
        numberOfMonths: [2,3],                
        dateFormat: 'dd/mm/yy',
        beforeShowDay: highlightDays
    });

    function highlightDays(date) {
        for (var i = 0; i < dates.length; i++) {
            if (dates[i] == date) {
                          return [true, 'highlight'];
                  }
          }
          return [true, ''];

 }   

});
 </script>

我的 CSS 是:

#highlight, .highlight {
    background-color: #cccccc;
}

日历出现了,但没有突出显示.我的代码哪里出了问题?如果有人可以提供帮助,那就太好了.

Well the calendar comes up, but there is nothing highlighted. Where is the problem in my code? If anyone could help that would be great.

另一个选项/解决方案可能是:禁用所有日期,但仅使数组中的日期可用.

Another option/solution could be: disable all dates, but make available only dates in an array.

谢谢!

推荐答案

告诉你一些问题...

1.var 日期 = [30/04/2010, 01/05/2010];

1 . var dates = [30/04/2010, 01/05/2010];

不会按预期存储您的日期...它会进行数学运算...

would not store your dates as expected... it will do math operations...

2. 将其更改为字符串,但采用以下格式:mm/dd/yy
因此,您应该具有以下内容:

2.  change it to string but in this format: mm/dd/yy
so, you should have something like:

var dates = ['04/30/2010', '05/01/2010'];

3. 使用这个功能:

3.  use this function:

function highlightDays(date) {
        for (var i = 0; i < dates.length; i++) {
            if (new Date(dates[i]).toString() == date.toString()) {              
                          return [true, 'highlight'];
                  }
          }
          return [true, ''];

 } 

4. CSS 为:

4.  CSS as:

td.highlight {
    background-color: red;
    border: 1px blue solid;
}

5. 演示

这篇关于JavaScript:jQuery Datepicker - 特定日期的简单突出显示,谁能提供帮助?(内有来源)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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