添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
逃跑的灭火器  ·  Flatpickr and ...·  7 小时前    · 
温暖的枕头  ·  Comment récupérer un ...·  1 周前    · 
奋斗的香蕉  ·  JAVA ...·  1 周前    · 
气势凌人的香菇  ·  JavaFX 8 DatePicker ...·  1 周前    · 
大力的足球  ·  pyspark.sql.functions. ...·  4 月前    · 
高大的山羊  ·  js ...·  8 月前    · 
严肃的苹果  ·  How to fix SYSLOG ...·  9 月前    · 

Events

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 when the associated text field gains focus. For an inline calendar, simply attach the datepicker to a div or span.

Keyboard interaction

While the datepicker is open, the following key commands are available:

PAGE UP : Move to the previous month. PAGE DOWN : Move to the next month. CTRL + PAGE UP : Move to the previous year. CTRL + PAGE DOWN : Move to the next year. CTRL + HOME : Open the datepicker if closed. CTRL / COMMAND + HOME : Move to the current month. CTRL / COMMAND + LEFT : Move to the previous day. CTRL / COMMAND + RIGHT : Move to the next day. CTRL / COMMAND + UP : Move to the previous week. CTRL / COMMAND + DOWN : Move to the next week. ENTER : Select the focused date. CTRL / COMMAND + END : Close the datepicker and erase the date. ESCAPE : Close the datepicker without selection.

Utility functions

$.datepicker.setDefaults( options )

Change the default options for all date pickers.

Use the option() method to change options for individual instances.

Code examples:

Set all date pickers to open on focus or a click on an icon.

$.datepicker.formatDate( format, date, options )

Format a date into a string value with a specified format.

The format can be combinations of the following:

  • d - day of month (no leading zero)
  • dd - day of month (two digit)
  • o - day of the year (no leading zeros)
  • oo - day of the year (three digit)
  • D - day name short
  • DD - day name long
  • m - month of year (no leading zero)
  • mm - month of year (two digit)
  • M - month name short
  • MM - month name long
  • y - year (two digit)
  • yy - year (four digit)
  • @ - Unix timestamp (ms since 01/01/1970)
  • ! - Windows ticks (100ns since 01/01/0001)
  • '...' - literal text
  • '' - single quote
  • anything else - literal text
  • There are also a number of predefined standard date formats available from $.datepicker :

  • ATOM - 'yy-mm-dd' (Same as RFC 3339/ISO 8601)
  • COOKIE - 'D, dd M yy'
  • ISO_8601 - 'yy-mm-dd'
  • RFC_822 - 'D, d M y' (See RFC 822)
  • RFC_850 - 'DD, dd-M-y' (See RFC 850)
  • RFC_1036 - 'D, d M y' (See RFC 1036)
  • RFC_1123 - 'D, d M yy' (See RFC 1123)
  • RFC_2822 - 'D, d M yy' (See RFC 2822)
  • RSS - 'D, d M y' (Same as RFC 822)
  • TICKS - '!'
  • TIMESTAMP - '@'
  • W3C - 'yy-mm-dd' (Same as ISO 8601)
  • Code examples:

    Display the date in ISO format. Produces "2007-01-26".

    $.datepicker.formatDate( "DD, MM d, yy", new Date( 2007, 7 - 1, 14 ), {
    dayNamesShort: $.datepicker.regional[ "fr" ].dayNamesShort,
    dayNames: $.datepicker.regional[ "fr" ].dayNames,
    monthNamesShort: $.datepicker.regional[ "fr" ].monthNamesShort,
    monthNames: $.datepicker.regional[ "fr" ].monthNames
    });

    $.datepicker.parseDate( format, value, options )

    Extract a date from a string value with a specified format.

    The format can be combinations of the following:

  • d - day of month (no leading zero)
  • dd - day of month (two digit)
  • o - day of year (no leading zeros)
  • oo - day of year (three digit)
  • D - day name short
  • DD - day name long
  • m - month of year (no leading zero)
  • mm - month of year (two digit)
  • M - month name short
  • MM - month name long
  • y - year (two digit)
  • yy - year (four digit)
  • @ - Unix timestamp (ms since 01/01/1970)
  • ! - Windows ticks (100ns since 01/01/0001)
  • '...' - literal text
  • '' - single quote
  • anything else - literal text
  • A number of exceptions may be thrown:

  • 'Invalid arguments' if either format or value is null
  • 'Missing number at position nn' if format indicated a numeric value that is not then found
  • 'Unknown name at position nn' if format indicated day or month name that is not then found
  • 'Unexpected literal at position nn' if format indicated a literal value that is not then found
  • 'Invalid date' if the date is invalid, such as '31/02/2007'
  • Code examples:

    Extract a date in ISO format.

    $.datepicker.parseDate( "DD, MM d, yy", "Samedi, Juillet 14, 2007", {
    shortYearCutoff: 20,
    dayNamesShort: $.datepicker.regional[ "fr" ].dayNamesShort,
    dayNames: $.datepicker.regional[ "fr" ].dayNames,
    monthNamesShort: $.datepicker.regional[ "fr" ].monthNamesShort,
    monthNames: $.datepicker.regional[ "fr" ].monthNames
    });

    $.datepicker.iso8601Week( date )

    Determine the week of the year for a given date: 1 to 53.

    This function uses the ISO 8601 definition of a week: weeks start on a Monday and the first week of the year contains January 4. This means that up to three days from the previous year may be included in the of first week of the current year, and that up to three days from the current year may be included in the last week of the previous year.

    This function is the default implementation for the calculateWeek option.

    Code examples:

    Find the week of the year for a date.

    $.datepicker.noWeekends

    Set as beforeShowDay function to prevent selection of weekends.

    We can provide the noWeekends() function into the beforeShowDay option which will calculate all the weekdays and provide an array of true / false values indicating whether a date is selectable.

    Code examples:

    Set the DatePicker so no weekend is selectable

    Localization

    Datepicker provides support for localizing its content to cater for different languages and date formats. Each localization is contained within its own file with the language code appended to the name, e.g., jquery.ui.datepicker-fr.js for French. The desired localization file should be included after the main datepicker code. Each localization file adds its options to the set of available localizations and automatically applies them as defaults for all instances. Localization files can be found at https://github.com/jquery/jquery-ui/tree/master/ui/i18n .

    The $.datepicker.regional attribute holds an array of localizations, indexed by language code, with "" referring to the default (English). Each entry is an object with the following attributes: closeText , prevText , nextText , currentText , monthNames , monthNamesShort , dayNames , dayNamesShort , dayNamesMin , weekHeader , dateFormat , firstDay , isRTL , showMonthAfterYear , and yearSuffix .

    You can restore the default localizations with:

    $.datepicker.setDefaults( $.datepicker.regional[ "" ] );

    And can then override an individual datepicker for a specific locale:

    $( selector ).datepicker( $.datepicker.regional[ "fr" ] );

    Theming

    The datepicker widget uses the jQuery UI CSS framework to style its look and feel. If datepicker specific styling is needed, the following CSS class names can be used for overrides or as keys for the classes option :

    ui-datepicker : The outer container of the datepicker. If the datepicker is inline, this element will additionally have a ui-datepicker-inline class. If the isRTL option is set, this element will additionally have a class of ui-datepicker-rtl . ui-datepicker-header : The container for the datepicker's header. ui-datepicker-prev : The control used to select previous months. ui-datepicker-next : The control used to select subsequent months. ui-datepicker-title : The container for the datepicker's title containing the month and year. ui-datepicker-month : The textual display of the month or a <select> element if the changeMonth option is set. ui-datepicker-year : The textual display of the year or a <select> element if the changeYear option is set. ui-datepicker-week-end : Cells containing weekend days. ui-datepicker-other-month : Cells containing days that occur in a month other than the currently selected month. ui-datepicker-unselectable : Cells containing days that are not selectable by the user. ui-datepicker-current-day : The cell containing the selected day. ui-datepicker-today : The cell containing today's date. ui-datepicker-buttonpane : The buttonpane that is used when the showButtonPanel option is set. ui-datepicker-current : The button used to select today's date. ui-datepicker-multi : The outermost container of a multiple month datepicker. This element can additionally have a ui-datepicker-multi-2 , ui-datepicker-multi-3 , or ui-datepicker-multi-4 class name depending on the number of months to display. ui-datepicker-group : Individual pickers within the group. This element will additionally have a ui-datepicker-group-first , ui-datepicker-group-middle , or ui-datepicker-group-last class name depending on its position within the group. This widget requires some functional CSS, otherwise it won't work. If you build a custom theme, use the widget's specific CSS file as a starting point. This widget manipulates its element's value programmatically, therefore a native change event may not be fired when the element's value changes. Creating a datepicker on an <input type="date"> is not supported due to a UI conflict with the native picker.

    Options

    altField Type: Selector or jQuery or Element Default: ""
    An input element that is to be updated with the selected date from the datepicker. Use the altFormat option to change the format of the date within this field. Leave as blank for no alternate field.
    Code examples:

    Initialize the datepicker with the altField option specified:

    Default: ""
    The dateFormat to be used for the altField option. This allows one date format to be shown to the user for selection purposes, while a different format is actually sent behind the scenes. For a full list of the possible formats see the formatDate function
    Code examples:

    Initialize the datepicker with the altFormat option specified:

    Default: false
    Set to true to automatically resize the input field to accommodate dates in the current dateFormat .
    Code examples:

    Initialize the datepicker with the autoSize option specified:

    Default: null
    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.

    beforeShowDay Type: Function ( Date date )

    Default: null
    A function that takes a date as a parameter and must return an array with: [0] : true / false indicating whether or not this date is selectable [1] : a CSS class name to add to the date's cell or "" for the default presentation [2] : an optional popup tooltip for this date The function is called for each day in the datepicker before it is displayed.

    buttonImage Type: String Default: ""
    A URL of an image to use to display the datepicker when the showOn option is set to "button" or "both" . If set, the buttonText option becomes the alt value and is not directly displayed.
    Code examples:

    Initialize the datepicker with the buttonImage option specified:

    Default: false
    Whether the button image should be rendered by itself instead of inside a button element. This option is only relevant if the buttonImage option has also been set.
    Code examples:

    Initialize the datepicker with the buttonImageOnly option specified:

    Default: "..."
    The text to display on the trigger button. Use in conjunction with the showOn option set to "button" or "both" .
    Code examples:

    Initialize the datepicker with the buttonText option specified:

    Default: jQuery.datepicker.iso8601Week
    A function to calculate the week of the year for a given date. The default implementation uses the ISO 8601 definition: weeks start on a Monday; the first week of the year contains the first Thursday of the year.
    Code examples:

    Initialize the datepicker with the calculateWeek option specified:

    Default: false
    Whether the year should be rendered as a dropdown instead of text. Use the yearRange option to control which years are made available for selection.
    Code examples:

    Initialize the datepicker with the changeYear option specified:

    Default: "Done"
    The text to display for the close link. Use the showButtonPanel option to display this button.
    Code examples:

    Initialize the datepicker with the closeText option specified:

    Default: true
    When true , entry in the input field is constrained to those characters allowed by the current dateFormat option.
    Code examples:

    Initialize the datepicker with the constrainInput option specified:

    Default: "Today"
    The text to display for the current day link. Use the showButtonPanel option to display this button.
    Code examples:

    Initialize the datepicker with the currentText option specified:

    Default: "mm/dd/yy"
    The format for parsed and displayed dates. For a full list of the possible formats see the formatDate function.
    Code examples:

    Initialize the datepicker with the dateFormat option specified:

    Default: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
    The list of long day names, starting from Sunday, for use as requested via the dateFormat option.
    Code examples:

    Initialize the datepicker with the dayNames option specified:

    Default: [ "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" ]
    The list of minimised day names, starting from Sunday, for use as column headers within the datepicker.
    Code examples:

    Initialize the datepicker with the dayNamesMin option specified:

    Default: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
    The list of abbreviated day names, starting from Sunday, for use as requested via the dateFormat option.
    Code examples:

    Initialize the datepicker with the dayNamesShort option specified:

    Default: null
    Set the date to highlight on first opening if the field is blank. Specify either an actual date via a Date object or as a string in the current dateFormat , or 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.
    Multiple types supported:
      Date : A date object containing the default date. Number : A number of days from today. For example 2 represents two days from today and -1 represents yesterday. String : A string in the format defined by the dateFormat option, or a relative date. Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today. Code examples:

      Initialize the datepicker with the defaultDate option specified:

      Default: "normal"
      Control the speed at which the datepicker appears, it may be a time in milliseconds or a string representing one of the three predefined speeds ("slow", "normal", "fast").
      Code examples:

      Initialize the datepicker with the duration option specified:

      Default: false
      When true , the current day link moves to the currently selected date instead of today.
      Code examples:

      Initialize the datepicker with the gotoCurrent option specified:

      Default: false
      Normally the previous and next links are disabled when not applicable (see the minDate and maxDate options). You can hide them altogether by setting this attribute to true .
      Code examples:

      Initialize the datepicker with the hideIfNoPrevNext option specified:

      The maximum selectable date. When set to null , there is no maximum.
      Multiple types supported:
        Date : A date object containing the maximum date. Number : A number of days from today. For example 2 represents two days from today and -1 represents yesterday. String : A string in the format defined by the dateFormat option, or a relative date. Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today. Code examples:

        Initialize the datepicker with the maxDate option specified:

        The minimum selectable date. When set to null , there is no minimum.
        Multiple types supported:
          Date : A date object containing the minimum date. Number : A number of days from today. For example 2 represents two days from today and -1 represents yesterday. String : A string in the format defined by the dateFormat option, or a relative date. Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today. Code examples:

          Initialize the datepicker with the minDate option specified:

          Default: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
          The list of full month names, for use as requested via the dateFormat option.
          Code examples:

          Initialize the datepicker with the monthNames option specified:

          Default: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
          The list of abbreviated month names, as used in the month header on each datepicker and as requested via the dateFormat option.
          Code examples:

          Initialize the datepicker with the monthNamesShort option specified:

          Default: false
          Whether the currentText , prevText and nextText options should be parsed as dates by the formatDate function, allowing them to display the target month names for example.
          Code examples:

          Initialize the datepicker with the navigationAsDateFormat option specified:

          Default: "Next"
          The text to display for the next month link. With the standard ThemeRoller styling, this value is replaced by an icon.
          Code examples:

          Initialize the datepicker with the nextText option specified:

          Number : The number of months to display in a single row. Array : An array defining the number of rows and columns to display. Code examples:

          Initialize the datepicker with the numberOfMonths option specified:

          Default: null
          Called 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.

          onClose Type: Function ( String dateText, Object inst )

    Default: null
    Called when the datepicker is closed, whether or not a date is selected. The function receives the selected date as text ( "" if none) and the datepicker instance as parameters. this refers to the associated input field.

    onSelect Type: Function ( String dateText, Object inst ) Default: null
    Called 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.

    onUpdateDatepicker Type: Function ( Object inst ) Default: null
    Called when the datepicker widget's DOM is updated. The function receives the datepicker instance as the only parameter. this refers to the associated input field. (version added: 1.13)

    prevText Type: String Default: "Prev"
    The text to display for the previous month link. With the standard ThemeRoller styling, this value is replaced by an icon.
    Code examples:

    Initialize the datepicker with the prevText option specified:

    Default: false
    Whether days in other months shown before or after the current month are selectable. This only applies if the showOtherMonths option is set to true .
    Code examples:

    Initialize the datepicker with the selectOtherMonths option specified:

    Default: "+10"
    The cutoff year for determining the century for a date (used in conjunction with dateFormat 'y'). Any dates entered with a year value less than or equal to the cutoff year are considered to be in the current century, while those greater than it are deemed to be in the previous century.
    Multiple types supported:
      Number : A value between 0 and 99 indicating the cutoff year. String : A relative number of years from the current year, e.g., "+3" or "-5" . Code examples:

      Initialize the datepicker with the shortYearCutoff option specified:

      Default: "show"
      The name of the animation used to show and hide the datepicker. Use "show" (the default), "slideDown" , "fadeIn" , any of the jQuery UI effects . Set to an empty string to disable animation.
      Code examples:

      Initialize the datepicker with the showAnim option specified:

      Default: false
      Whether to display a button pane underneath the calendar. The button pane contains two buttons, a Today button that links to the current day, and a Done button that closes the datepicker. The buttons' text can be customized using the currentText and closeText options respectively.
      Code examples:

      Initialize the datepicker with the showButtonPanel option specified:

      Default: 0
      When displaying multiple months via the numberOfMonths option, the showCurrentAtPos option defines which position to display the current month in.
      Code examples:

      Initialize the datepicker with the showCurrentAtPos option specified:

      Default: "focus"
      When the datepicker should appear. The datepicker can appear when the field receives focus ( "focus" ), when a button is clicked ( "button" ), or when either event occurs ( "both" ).
      Code examples:

      Initialize the datepicker with the showOn option specified:

      Default: {}
      If using one of the jQuery UI effects for the showAnim option, you can provide additional properties for that animation using this option.
      Code examples:

      Initialize the datepicker with the showOptions option specified:

      Default: false
      Whether to display dates in other months (non-selectable) at the start or end of the current month. To make these days selectable use the selectOtherMonths option.
      Code examples:

      Initialize the datepicker with the showOtherMonths option specified:

      Default: false
      When true , a column is added to show the week of the year. The calculateWeek option determines how the week of the year is calculated. You may also want to change the firstDay option.
      Code examples:

      Initialize the datepicker with the showWeek option specified:

      Default: "Wk"
      The text to display for the week of the year column heading. Use the showWeek option to display this column.
      Code examples:

      Initialize the datepicker with the weekHeader option specified:

      Default: "c-10:c+10"
      The range of years displayed in the year drop-down: either relative to today's year ( "-nn:+nn" ), relative to the currently selected year ( "c-nn:c+nn" ), absolute ( "nnnn:nnnn" ), or combinations of these formats ( "nnnn:-nn" ). Note that this option only affects what appears in the drop-down, to restrict which dates may be selected use the minDate and/or maxDate options.
      Code examples:

      Initialize the datepicker with the yearRange option specified:

      Removes the datepicker functionality completely. This will return the element back to its pre-init state.
      • This method does not accept any arguments.
      Code examples:

      Invoke the destroy method:

      dialog( date [, onSelect ] [, options ] [, pos ] ) Returns: jQuery ( plugin only )
      Opens the datepicker in a dialog box.
      Type: String or Date
      The initial date.
      onSelect
      Type: Function ()
      A callback function when a date is selected. The function receives the date text and date picker instance as parameters.
      options
      Type: Options
      The new options for the date picker.
      Type: Number[2] or MouseEvent
      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.
      Code examples:

      Invoke the dialog method:

      getDate() Returns: Date
      Returns the current date for the datepicker or null if no date has been selected.
      • This method does not accept any arguments.
      Code examples:

      Invoke the getDate method:

      Determine whether a date picker has been disabled.
      • This method does not accept any arguments.
      Code examples:

      Invoke the isDisabled method:

      Gets the value currently associated with the specified optionName .

      Note: For options that have objects as their value, you can get the value of a specific key by using dot notation. For example, "foo.bar" would get the value of the bar property on the foo option.

      optionName
      Type: String
      The name of the option to get.
      Code examples:

      Invoke the method:

      option() Returns: PlainObject
      Gets an object containing key/value pairs representing the current datepicker options hash.
      • This signature does not accept any arguments.
      Code examples:

      Invoke the method:

      option( options ) Returns: jQuery ( plugin only )
      Sets one or more options for the datepicker.
      options
      Type: Object
      A map of option-value pairs to set.
      Code examples:

      Invoke the method:

      refresh() Returns: jQuery ( plugin only )
      Redraw the date picker, after having made some external modifications.
      • This method does not accept any arguments.
      Code examples:

      Invoke the refresh method:

      setDate( date ) Returns: jQuery ( plugin only )
      Sets the date for the datepicker. The new date may be a Date object or a string in the current date format (e.g., "01/26/2009" ), 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 to clear the selected date.
      Type: String or Date
      The new date.
      Code examples:

      Invoke the setDate method:

      show() Returns: jQuery ( plugin only )
      Open the date picker. If the datepicker is attached to an input, the input must be visible for the datepicker to be shown.
      • This method does not accept any arguments.
      Code examples:

      Invoke the show method:

      Returns a jQuery object containing the datepicker.
      • This method does not accept any arguments.
      Code examples:

      Invoke the widget method:

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="utf-8">
      <title>datepicker demo</title>
      <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.3/themes/smoothness/jquery-ui.css">
      <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
      <script src="https://code.jquery.com/ui/1.13.3/jquery-ui.js"></script>
      </head>
      <body>
      <div id="datepicker"></div>
      <script>
      $( "#datepicker" ).datepicker();
      </script>
      </body>
      </html>

      Web hosting by Digital Ocean | CDN by Fastly | Powered by WordPress