The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. You can customize the date format and language, restrict the selectable date ranges and add in buttons and other navigation options easily.
By default, the datepicker calendar opens in a small overlay onFocus and closes automatically onBlur or when a date if selected. For an inline calendar, simply attach the datepicker to a div or span.
You can use keyboard shortcuts to drive the datepicker:
$("#datepicker").datepicker();
<!DOCTYPE html> <html> <head> <link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" /> <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script> <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script> <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.datepicker.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#datepicker").datepicker(); }); </script> </head> <body style="font-size:62.5%;"> <div type="text" id="datepicker"></div> </body> </html>
Can be a function that takes an input field and current datepicker instance and returns an options object to update the datepicker with. It is called just before the datepicker is displayed.
beforeShow
event as an init option.
$('.selector').datepicker({
beforeShow: function(input) { ... }
});
The function takes a date as a parameter and must return an array with [0] equal to true/false indicating whether or not this date is selectable, [1] equal to a CSS class name(s) or '' for the default presentation and [2] an optional popup tooltip for this date. It is called for each day in the datepicker before is it displayed.
beforeShowDay
event as an init option.
$('.selector').datepicker({
beforeShowDay: function(date) { ... }
});
Allows you to define your own event when the datepicker moves to a new month and/or year. The function receives the selected year, month (1-12), and the datepicker instance as parameters. this
refers to the associated input field.
onChangeMonthYear
event as an init option.
$('.selector').datepicker({
onChangeMonthYear: function(year, month, inst) { ... }
});
Allows you to define your own event when the datepicker is closed, whether or not a date is selected. The function receives the selected date as text and the datepicker instance as parameters. this
refers to the associated input field.
onClose
event as an init option.
$('.selector').datepicker({
onClose: function(dateText, inst) { ... }
});
Allows you to define your own event when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this
refers to the associated input field.
onSelect
event as an init option.
$('.selector').datepicker({
onSelect: function(dateText, inst) { ... }
});
Remove the datepicker functionality completely. This will return the element back to its pre-init state.
Disable the datepicker.
Enable the datepicker.
Get or set any datepicker option. If no value is specified, will act as a getter.
Open a datepicker in a "dialog" box.
dateText: the initial date for the date picker.
onSelect: A callback function when a date is selected. The function receives the date text and date picker instance as parameters.
settings: The new settings for the date picker.
pos: The position of the top/left of the dialog as [x, y] or a MouseEvent that contains the coordinates. If not specified the dialog is centered on the screen.
Determine whether a date picker has been disabled.
Close a previously opened date picker.
speed: The speed at which to close the date picker.
Call up a previously attached date picker.
Returns the current date for the datepicker.
Sets the current date for the datepicker. The new date may also be a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null for today.
The jQuery UI Datepicker plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures. We recommend using the ThemeRoller tool to create and download custom themes that are easy to build and maintain.
If a deeper level of customization is needed, there are widget-specific classes referenced within the ui.datepicker.css stylesheet that can be modified. These classes are highlighed in bold below.
Note: This is a sample of markup generated by the datepicker plugin, not markup you should use to create a datepicker. The only markup needed for that is <input type="text" /> or <div></div>.