jQuery Datepicker Beforeshowday两个日期数组

时间:2014-01-09 03:26:10

标签: javascript jquery arrays datepicker

我有一个用于禁用日期的数组,另一个用于突出显示日期。有没有办法对此进行编码?

e.g:

beforeShowDay: function(date){
    var unavilble = jQuery.datepicker.formatDate('yy/mm/dd', date);
    var newstring = [ arrayable.indexOf(unavilble) == -1 ];
    return newstring;
    },

第二阵列:

var datet = ['2014/01/19', '2014/01/20'];
        //tips are optional but good to have
var tips  = ['some description','some other description'];      

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

1 个答案:

答案 0 :(得分:2)

尝试类似

的内容
var datet = ['2014/01/19', '2014/01/20'];
//tips are optional but good to have
var tips = ['some description', 'some other description'];
var arrayable = ['2014/01/01', '2014/01/08', '2014/01/15', '2014/01/22', '2014/01/29']
$('input').datepicker({
    dateFormat: 'yy/mm/dd',
    beforeShowDay: function (date) {
        var datestring = jQuery.datepicker.formatDate('yy/mm/dd', date);
        var hindex = $.inArray(datestring, datet);
        if (hindex > -1) {
            return [true, 'highlight', tips[hindex]];
        }
        var aindex = $.inArray(datestring, arrayable);
        return [aindex == -1]
    }
})

演示:Fiddle