1

I'm use jquery Datepicker [link:http://docs.jquery.com/UI/Datepicker] now,and if I want Set some date to highlight, not just highlight the date now, how can I set the option?

For example: enter image description here

There I want 24/09/2011, 25/09/2011 and 27/09/2011 to highlight.

Shamrocker
  • 121
  • 2
  • 11
  • Seen this question? http://stackoverflow.com/questions/2385332/jquery-datepicker-highlight-dates – itsmatt Sep 23 '11 at 02:33
  • thanks, I found better http://stackoverflow.com/questions/6857025/highlight-dates-in-jquery-ui-datepicker – Shamrocker Sep 23 '11 at 02:36
  • [This discussion](http://groups.google.com/group/jquery-ui/browse_thread/thread/5500b46e83d41bc1/6927a39ce0a01625) covers it as well. – Rusty Fausak Sep 23 '11 at 02:37

1 Answers1

4

You'll have to use the beforeShowDay option:

var dates = []; // array of the dates you want to highlight, stored as strings

$('selector').datepicker({
    beforeShowDay: function(date) {
        if ($.inArray(date.toString(), dates) != -1) {
            return [true, 'highlight'];
        }
    }
});

See this question for more information:

Can the jQuery UI Datepicker be made to disable Saturdays and Sundays (and holidays)?

Community
  • 1
  • 1
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • The param dates, can I defined it as [new Date(2011, 8, 7),new Date(2011, 8, 20)]; and if ($.inArray(date, dates) != -1) . – Shamrocker Sep 23 '11 at 03:24
  • @Shamrocker - Nope. In JavaScript, objects are compared by reference.  For example `{a:'a'} == {a:'a'}` will return false. To compare your dates, you gave to convert them to strings. Use this: `[(new Date(2011, 8, 7)).toString(), (new Date(2011, 8, 20)).toString];` and `if ($.inArray(date.toString(), dates) != -1)`. – Joseph Silber Sep 23 '11 at 15:02