jqueryui时间插件_满足您所有日历要求的jQueryUI Datepicker插件

jqueryui时间插件

jQuery provides a variety of Calendar Plugins that would allow you to integrate calendar features to your websites. These plugins are very easy to use and we can easily include these plugins in our web applications. In this post, we are going to discuss about one of the jQuery calendar plugins, jQuery UI Datepicker.

jQuery提供了各种日历插件 ,可让您将日历功能集成到您的网站。 这些插件非常易于使用,我们可以轻松地将这些插件包含在我们的Web应用程序中。 在本文中,我们将讨论jQuery日历插件之一jQuery UI Datepicker

jQueryUI日期选择器 (jQueryUI Datepicker)

The jQueryUI Datepicker plugin allow us to select a date from a popup or an in-line calendar. This plugin provide several options to customize the date format, localize calendar, restrict date range, and select a date range and many more. I would like to get down to the details.

jQueryUI Datepicker插件允许我们从弹出窗口或嵌入式日历中选择日期。 该插件提供了多个选项来自定义日期格式,本地化日历,限制日期范围以及选择日期范围等等。 我想详细介绍一下。

内容 (Contents)

jQueryUI Datepicker选项 (jQueryUI Datepicker Options)

In this section, we will discuss about different options available to customize the jQueryUI Datepicker plugin. We have used many of these options in the jQueryUI Datepicker in Action section.

在本节中,我们将讨论可用于自定义jQueryUI Datepicker插件的不同选项。 我们在jQueryUI Datepicker in Action部分中使用了许多这些选项。

OptionsSyntaxDescription
altField$( “.selector” ).datepicker({ altField: “#actualDate” });Alternate input field, updated with the selected date from the datepicker.
altFormat$( “.selector” ).datepicker({ altFormat: “yy-mm-dd” });Date format of the altField option.
appendText$( “.selector” ).datepicker({ appendText: “(yyyy-mm-dd)” });Text that is displayed next to the the input field.
autoSize$( “.selector” ).datepicker({ autoSize: true });Automatically resize input field if it is set to true.
beforeShowThis option is a callback function that is invoked just before displaying  datepicker.
buttonImage$( “.selector” ).datepicker({ buttonImage: “/images/datepicker.gif” });Display the datepicker with URL of an image \ when the showOn option is set to “button” or “both”.
buttonImageOnlyType$( “.selector” ).datepicker({ buttonImageOnly: true });Indicate whether the button image should be rendered inside button.
buttonTextType$( “.selector” ).datepicker({ buttonText: “Choose” });Display text on the trigger button.
calculateWeek$( “.selector” ).datepicker({ calculateWeek: myWeekCalc });Calculate the week of the year for the selected date.
changeMonth$( “.selector” ).datepicker({ changeMonth: true });Month will be rendered as a drop down if it is set to true.
changeYear$( “.selector” ).datepicker({ changeYear: true });Year will be rendered as a drop down if it is set to true.
closeText$( “.selector” ).datepicker({ closeText: “Close” });Display text on the close button.showButtonPanel option is used to display this button
constrainInput$( “.selector” ).datepicker({ constrainInput: false });Input field is constrained to those characters allowed by the current dateFormat option when this is set to true.
currentText$( “.selector” ).datepicker({ currentText: “Now” });Display text on current day link. showButtonPanel option is used to display this button
dateFormat$( “.selector” ).datepicker({ dateFormat: “yy-mm-dd” });Format for displayed dates.
dayNames$( “.selector” ).datepicker({ dayNames: [ “Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday” ]});List of day names.
dayNamesMin$( “.selector” ).datepicker({ dayNamesMin: [ “Di”, “Lu”, “Ma”, “Me”, “Je”, “Ve”, “Sa” ] });List of minimized day names.
dayNamesShort$( “.selector” ).datepicker({ dayNamesShort: [ “Dim”, “Lun”, “Mar”, “Mer”, “Jeu”, “Ven”, “Sam” ] });List of abbreviated day names.
defaultDate$( “.selector” ).datepicker({ defaultDate: +7 });Set the date to highlight on first opening if the field is blank
duration$( “.selector” ).datepicker({ duration: “slow” });Vary the speed of date picker appearance.
firstDay$( “.selector” ).datepicker({ firstDay: 1 });Set the first day of the week.
gotoCurrent$( “.selector” ).datepicker({ gotoCurrent: true });The current day link moves to the currently selected date instead of today if it is set to true.
hideIfNoPrevNext$( “.selector” ).datepicker({ hideIfNoPrevNext: true });Hide  previous and next links if the value is set to true.
isRTL$( “.selector” ).datepicker({ isRTL: true });Check if the the current language is drawn from right to left.
maxDate$( “.selector” ).datepicker({ maxDate: “+1m +1w” });Maximum selectable date.
minDate$( “.selector” ).datepicker({ minDate: new Date(2007, 1 – 1, 1) });Minimum selectable date.
monthNames$( “.selector” ).datepicker({ monthNames: [ “Januar”, “Februar”, “Marts”, “April”, “Maj”, “Juni”, “Juli”, “August”, “September”, “Oktober”, “November”, “December” ] });List of month names
monthNamesShort$( “.selector” ).datepicker({ monthNamesShort: [ “Jan”, “Feb”, “Mar”, “Apr”, “Maj”, “Jun”, “Jul”, “Aug”, “Sep”, “Okt”, “Nov”, “Dec” ] });List of abbreviated month names.
navigationAsDateFormat$( “.selector” ).datepicker({ navigationAsDateFormat: true });Check whether to navigate as
nextText$( “.selector” ).datepicker({ nextText: “Later” });The text to display for the next month link
numberOfMonths$( “.selector” ).datepicker({ numberOfMonths: [ 2, 3 ] });The number of months displayed at once.
onChangeMonthYearThe callback function called when the month or year is changed.
onCloseThe callback function called when the datepicker is closed.
onSelectThe callback function called when the date is selected from the datepicker.
prevText$( “.selector” ).datepicker({ prevText: “Earlier” });Display text on the previous link.
selectOtherMonths$( “.selector” ).datepicker({ selectOtherMonths: true });Whether days in other months shown before or after the current month are selectable.
shortYearCutoff$( “.selector” ).datepicker({ shortYearCutoff: 50 });The cutoff year for determining the century for a date.
showAnim$( “.selector” ).datepicker({ showAnim: “fold” });The animation effects used to display the datepicker.
showButtonPanel$( “.selector” ).datepicker({ showButtonPanel: true });Set to true will display the button in the datepicker.
showCurrentAtPos$( “.selector” ).datepicker({ showCurrentAtPos: 3 });Defines which position to display the current month while displaying multiple months.
showMonthAfterYear$( “.selector” ).datepicker({ showMonthAfterYear: true });Set to true will display the month after the year in the header.
showOn$( “.selector” ).datepicker({ showOn: “both” });Indicate when the date picker should appear.
showOptions$( “.selector” ).datepicker({ showOptions: { direction: “up” } });Additional animation options.
showOtherMonths$( “.selector” ).datepicker({ showOtherMonths: true });Whether to show the dates in other months at the start or end of the current month.
showWeek$( “.selector” ).datepicker({ showWeek: true });A column is added to to display the week of the year.
stepMonths$( “.selector” ).datepicker({ stepMonths: 3 });number of months to be moved when we click on prev or next links.
weekHeader$( “.selector” ).datepicker({ weekHeader: “W” });Display text for the week of the year column heading.
yearRange$( “.selector” ).datepicker({ yearRange: “2002:2012” });Range of years in the drop down.
yearSuffix$( “.selector” ).datepicker({ yearSuffix: “CE” });Additional text to display after the year.
选件 句法 描述
altField $(“ .selector”).datepicker({altField:“ #actualDate”}); 备用输入字段,使用从日期选择器中选择的日期进行更新。
altFormat $(“ .selector”).datepicker({altFormat:“ yy-mm-dd”}); altField选项的日期格式。
appendText $(“ .selector”).datepicker({appendText:“(yyyy-mm-dd)”}); 在输入字段旁边显示的文本。
自动尺寸 $(“ .selector”).datepicker({autoSize:true}); 如果将输入字段设置为true,则自动调整其大小。
beforeShow 此选项是一个回调函数,仅在显示日期选择器之前被调用。
buttonImage $(“ .selector”).datepicker({buttonImage:“ /images/datepicker.gif”}); 当showOn选项设置为“ button”或“ both”时,显示带有图像URL的日期选择器。
buttonImageOnlyType $(“ .selector”).datepicker({buttonImageOnly:true}); 指示是否应在按钮内部渲染按钮图像。
buttonTextType $(“ .selector”).datepicker({buttonText:“ Choose”}); 在触发按钮上显示文本。
计算周 $(“ .selector”).datepicker({calculateWeek:myWeekCalc}); 计算所选日期的一年中的星期。
changeMonth $(“ .selector”).datepicker({changeMonth:true}); 如果设置为true,则月份将显示为下拉列表。
changeYear $(“ .selector”).datepicker({changeYear:true}); 如果将年份设置为true,则年份将显示为下拉列表。
closeText $(“ .selector”).datepicker({closeText:“ Close”}); 在关闭按钮上显示文本。showButtonPanel选项用于显示此按钮
约束输入 $(“ .selector”).datepicker({constrainInput:false}); 当此字段设置为true时,输入字段将限于当前dateFormat选项允许的那些字符。
currentText $(“ .selector”).datepicker({currentText:“ Now”}); 在当天链接上显示文本。 showButtonPanel选项用于显示此按钮
日期格式 $(“ .selector”).datepicker({dateFormat:“ yy-mm-dd”}); 显示日期的格式。
dayNames $(“ .selector”).datepicker({dayNames:[“ Sunday”,“ Monday”,“ Tuesday”,“ Wednesday”,“ Thursday”,“ Friday”,“ Saturday”]}); 日期名称列表。
dayNamesMin $(“ .selector”)。datepicker({dayNamesMin:[“ Di”,“ Lu”,“ Ma”,“ Me”,“ Je”,“ Ve”,“ Sa”]}); 最小化的日期名称列表。
dayNamesShort $(“ .selector”).datepicker({dayNamesShort:[[Dim],“ Lun”,“ Mar”,“ Mer”,“ Jeu”,“ Ven”,“ Sam”]}); 缩写的日期名称列表。
defaultDate $(“ .selector”).datepicker({defaultDate:+7}); 如果该字段为空白,则设置日期以突出显示第一次打开
持续时间 $(“ .selector”).datepicker({duration:“ slow”}); 更改日期选择器显示的速度。
第一天 $(“ .selector”).datepicker({firstDay:1}); 设置一周的第一天。
gotoCurrent $(“ .selector”).datepicker({gotoCurrent:true}); 如果将当前日期链接设置为true,则移动到当前选择的日期,而不是今天。
hideIfNoPrevNext $(“ .selector”).datepicker({hideIfNoPrevNext:true}); 如果该值设置为true,则隐藏上一个和下一个链接。
isRTL $(“ .selector”).datepicker({isRTL:true}); 检查当前语言是否从右到左绘制。
maxDate $(“ .selector”).datepicker({maxDate:“ + 1m + 1w”}); 最大可选日期。
minDate $(“ .selector”).datepicker({minDate:new Date(2007,1 – 1,1)}); 最小可选日期。
monthNames $(“ .selector”).datepicker({monthNames:[“ Januar”,“ Februar”,“ Marts”,“ April”,“ Maj”,“ Juni”,“ Juli”,“ August”,“ September”, “十月”,“十一月”,“十二月”]}); 月份名称列表
monthNamesShort $(“ .selector”).datepicker({monthNamesShort:[“ Jan”,“ Feb”,“ Mar”,“ Apr”,“ Maj”,“ Jun”,“ Jul”,“ Aug”,“ Sep”, “ Okt”,“ Nov”,“ Dec”]}); 缩写月份名称列表。
navigationAsDateFormat $(“ .selector”).datepicker({navigationAsDateFormat:true}); 检查是否导航为
nextText $(“ .selector”).datepicker({nextText:“ Later”}); 下个月要显示的文字链接
numberOfMonths $(“ .selector”).datepicker({numberOfMonths:[2,3]}); 一次显示的月数。
onChangeMonthYear 更改月份或年份时调用的回调函数。
onClose 关闭日期选择器时调用的回调函数。
onSelect 从日期选择器中选择日期时调用的回调函数。
prevText $(“ .selector”).datepicker({prevText:“早期”}); 在上一个链接上显示文本。
selectOtherMonths $(“ .selector”).datepicker({selectOtherMonths:true}); 是否可以选择当前月份之前或之后显示的其他月份中的天。
shortYearCutoff $(“ .selector”).datepicker({shortYearCutoff:50}); 确定日期的世纪的截止年份。
showAnim $(“ .selector”).datepicker({showAnim:“ fold”}); 用于显示日期选择器的动画效果。
showButtonPanel $(“ .selector”).datepicker({showButtonPanel:true}); 设置为true将在日期选择器中显示按钮。
showCurrentAtPos $(“ .selector”).datepicker({showCurrentAtPos:3}); 定义显示多个月份的同时显示当前月份的位置。
showMonthAfterYear $(“ .selector”).datepicker({showMonthAfterYear:true}); 设置为true将在标题中显示年份之后的月份。
showOn $(“ .selector”).datepicker({showOn:“ both”}); 指示日期选择器应出现的时间。
showOptions $(“ .selector”).datepicker({showOptions:{方向:“向上”}}); 其他动画选项。
showOtherMonths $(“ .selector”).datepicker({showOtherMonths:true}); 在当前月份的开始或结束时显示其他月份中的日期。
showWeek $(“ .selector”).datepicker({showWeek:true}); 将添加一列以显示一年中的星期。
stepMonths $(“ .selector”).datepicker({stepMonths:3}); 单击上一个或下一个链接时要移动的月数。
weekHeader $(“ .selector”).datepicker({weekHeader:“ W”}); 显示一年中的星期几列标题的文本。
yearRange $(“ .selector”).datepicker({yearRange:“ 2002:2012”}); 在下拉范围内。
yearSuffix $(“ .selector”).datepicker({yearSuffix:“ CE”}); 年后要显示的其他文本。

This table briefly describes all the available options in the jQueryUI Datepicker plugin.

下表简要描述了jQueryUI Datepicker插件中的所有可用选项。

Back To Top

回到顶部

jQueryUI Datepicker方法 (jQueryUI Datepicker Methods)

In this section, we will look into the jQueryUI Datepicker plugin methods and its syntax. These methods are very useful when you deal with the datepicker plugin.

在本节中,我们将研究jQueryUI Datepicker插件方法及其语法。 这些方法在处理datepicker插件时非常有用。

MethodsSyntaxDescription
destroy$(“.selector”).
datepicker(“destroy”);
Removes the datepicker functionality completely and return the element back to its pre-init state.
dialog$( “.selector” ).
datepicker( “dialog”, “10/10/2014” );
Opens the datepicker in a dialog box.Parameters are : date , onSelect , settings , pos.
getDate$( “.selector” ).
datepicker( “getDate” );
Returns the current date for the datepicker or null if no date has been selected.
hide$( “.selector” ).
datepicker( “hide” );
Close a previously opened date picker.
isDisabled$( “.selector” ).
datepicker( “isDisabled” );
Determine whether a date picker has been disabled.
option$( “.selector” ).
datepicker( “option”);
Gets an object containing key/value pairs representing the current datepicker options hash.
refresh$( “.selector” ).
datepicker( “refresh” );
Refresh the date picker after making any modification
setDate$( “.selector” ).
datepicker( “setDate”, “10/10/2014” );
This method is used to set the date for the datepicker.
show$( “.selector” ).
datepicker( “show” );
Display the date picker.
widget$( “.selector” ).
datepicker( “widget” );
Returns a jQuery object that contains the datepicker.
方法 句法 描述
破坏 $(“。selector”)。
datepicker(“ destroy”);
完全删除datepicker功能,并将元素返回到其初始状态。
对话 $(“ .selector”)。
datepicker(“ dialog”,“ 10/10/2014”);
在对话框中打开日期选择器,参数为:date,onSelect,设置,pos。
getDate $(“ .selector”)。
datepicker(“ getDate”);
返回日期选择器的当前日期;如果未选择日期,则返回null。
隐藏 $(“ .selector”)。
datepicker(“隐藏”);
关闭以前打开的日期选择器。
被禁用 $(“ .selector”)。
datepicker(“ isDisabled”);
确定是否禁用了日期选择器。
选项 $(“ .selector”)。
datepicker(“选项”);
获取一个对象,该对象包含表示当前datepicker选项哈希的键/值对。
刷新 $(“ .selector”)。
datepicker(“刷新”);
进行任何修改后刷新日期选择器
设置日期 $(“ .selector”)。
datepicker(“ setDate”,“ 10/10/2014”);
此方法用于设置日期选择器的日期。
表演 $(“ .selector”)。
datepicker(“ show”);
显示日期选择器。
小部件 $(“ .selector”)。
datepicker(“ widget”);
返回一个包含日期选择器的jQuery对象。

Back To Top

回到顶部

运行中的jQueryUI Datepicker (jQueryUI Datepicker in Action)

In this section we will try different examples to explore the uses of jQueryUI Datepicker plugin.

在本节中,我们将尝试不同的示例来探索jQueryUI Datepicker插件的用法。

默认功能 (Default Functionality)

The following example demonstrates the default functionality of jQueryUI Datepicker plugin. It does not take any parameters. The datepicker is attached to a standard input field. Click on the field to open calendar with default functionality. This will be closed after selecting a date or when it is out of focus or you can hit esc button to close it.

以下示例演示了jQueryUI Datepicker插件的默认功能。 它不带任何参数。 日期选择器附加到标准输入字段。 单击该字段以打开具有默认功能的日历。 选择日期后或日期不清晰时,它将关闭,或者您可以按esc按钮将其关闭。

datepicker-default.html

datepicker-default.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker - Default</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>

  <script>
  $(function() {
    $( "#date_picker" ).datepicker();
  });
  </script>
</head>

<body>
    <p>Click Here to Enter the date : <input type="text" id="date_picker"></p>
</body>
</html>

You will see the following output if you click on the input field.

datepicker-default

如果单击输入字段,将看到以下输出。

带有动画的日期选择器 (Datepicker with Animation)

The following example demonstrates the jQuery datepicker plugin with animation. You can try animating the datepicker by selecting an option from the drop down and click on the input field shown in the example.

以下示例演示了带有动画的jQuery datepicker插件。 您可以通过从下拉列表中选择一个选项并单击示例中显示的输入字段来尝试使日期选择器动画化。

datepicker-anim.html

datepicker-anim.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker - Animation</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#date_picker" ).datepicker();
    $( "#effects" ).change(function() {
      $( "#date_picker" ).datepicker( "option", "showAnim", $( this ).val() );
    });
  });
  </script>
</head>
<body>

<p>Select Animation:<br>
  <select id="effects">
    <option value="show">Show (default)</option>
    <option value="bounce">Bounce</option>
    <option value="slideDown">Slide down</option>
    <option value="fadeIn">Fade in</option>
    <option value="blind">Blind</option>
    <option value="fold">Fold </option>
    <option value="">None</option>
  </select>
</p>
<p>Click Here to Enter Date: <input type="text" id="date_picker" size="25"></p>

</body>
</html>

You will see the following output if you click on the input field.

datepicker-anim

如果单击输入字段,将看到以下输出。

内联日期选择器 (In-line Datepicker)

The following example demonstrates the in-line jQuery datepicker plugin.

以下示例演示了嵌入式jQuery datepicker插件。

datepicker-inline.html

datepicker-inline.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker - Inline</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>

  <script>
  $(function() {
    $( "#date_picker" ).datepicker();
  });
  </script>
</head>
<body>
 
Date In-Line : <div id="date_picker"></div>
 
</body>
</html>

You will see the following output if you click on the input field.

datepicker-inline

如果单击输入字段,将看到以下输出。

带按钮的日期选择器 (Datepicker with Button)

The following example demonstrates the jQuery datepicker with buttons. This plugin display a Today button to select today’s date and another button called Done to close the datepicker.

下面的示例演示了带有按钮的jQuery datepicker。 此插件显示“ Today按钮以选择今天的日期,并显示另一个按钮“ Done以关闭日期选择器。

datepicker-button.html

datepicker-button.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker - Button</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>

  <script>
  $(function() {
    $( "#date_picker" ).datepicker( {
    showButtonPanel: true
    });
  });
  </script>
</head>
<body>
<p>Click Here To Enter Date: <input type="text" id="date_picker"></p>
</body>
</html>

You will see the following output if you click on the input field.

datepicker-button

如果单击输入字段,将看到以下输出。

Datepicker图标 (Datepicker Icon)

The following example demonstrates the datepicker with icon trigger. You can view the datepicker by clicking on the icon next to the input field.

下面的示例演示带有图标触发器的日期选择器。 您可以通过单击输入字段旁边的图标来查看日期选择器。

datepicker-icon.html

datepicker-icon.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker - Icon</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#date_picker" ).datepicker({
      showOn: "button",
      buttonImage: "/images/calendar-icon.png",
      buttonImageOnly: true,
      buttonText: "Select date"
    });
  });
  </script>
</head>
<body>
 
<p>Click on the Icon to Enter Date: <input type="text" id="date_picker"></p>
 
</body>
</html>

You will see the following output if you click on the icon next to the input field.

datepicker-icon

如果单击输入字段旁边的图标,将看到以下输出。

格式化日期 (Format Date)

The following example demonstrates the datepicker using dateFormat option in the JQueryUI Datepicker plugin. We have used dateFormat:"DD, d MM, yy" in this example. There are a number of dataFormat options available with this plugin.

下面的示例演示了JQueryUI Datepicker插件中使用dateFormat选项的datepicker。 在此示例中dateFormat:"DD, d MM, yy"我们使用了dateFormat:"DD, d MM, yy" 。 此插件有许多dataFormat选项可用。

datepicker-format.html

datepicker-format.html

<!doctype html>
<html>
 <head>
  <title>jQuery UI Datepicker - Format</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
  <script>
         $(function() {
            $( "#date_picker" ).datepicker({
               appendText:"(Full - DD, d MM, yy)",
               dateFormat:"DD, d MM, yy"
            });
         });
   </script>
 </head>
  <body>
     <p>Click Here To Enter Date: <input type="text" id="date_picker" size=30></p>
  </body>
</html>

You will see the following output on your browser.

datepicker-format

您将在浏览器中看到以下输出。

选择日期范围 (Select Date Range)

The following example demonstrates the datepicker to select range of dates.

以下示例演示了选择日期范围的日期选择器。

datepicker-selectRange.html

datepicker-selectRange.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker - Select Range</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
    <script>
  $(function() {
    $( "#from" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    $( "#to" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
  });
  </script>
</head>
<body>
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">To</label>
<input type="text" id="to" name="to">
</body>
</html>

You will see the following output on your browser.

datepicker-selectRange

您将在浏览器中看到以下输出。

限制日期范围 (Restrict Date Range)

The following example demonstrates how to restrict the range of dates. We use minDate and maxDate options for this.

下面的示例演示如何限制日期范围。 我们maxDate使用minDatemaxDate选项。

datepicker-restrictRange.html

datepicker-restrictRange.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker – Restrict Range</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>

  <script>
  $(function() {
      $( "#date_picker" ).datepicker({
        numberOfMonths: 3,minDate: -20, maxDate: "+1M +10D"
      });
  });
  </script>
</head>
<body>
<p>Clik Here to Enter the Date: <input type="text" id="date_picker"></p>
</body>
</html>

You will see the following output on your browser.

datepicker-restrictRange

您将在浏览器中看到以下输出。

填充备用字段 (Populate alternate field)

The following example demonstrates how to populate an alternate field using the altField and altFormat options.

下面的示例演示如何使用altFieldaltFormat选项填充备用字段。

datepicker-alt.html

datepicker-alt.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker – Alt</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>

    <script>
  $(function() {
    $( "#date_picker" ).datepicker({
      altField: "#alternate",
      altFormat: "DD, d MM, yy"
    });
  });
  </script>
</head>
<body>
<p>Click here To Enter Date: <input type="text" id="date_picker"> Alternate Date:<input type="text" id="alternate" size="30"></p>
</body>
</html>

You will see the following output on your browser.

datepicker-alt

您将在浏览器中看到以下输出。

显示多个月 (Display Multiple Months)

The following example demonstrates the datepicker with multiple months in a single datepicker. We can set the numberOfMonths option to an integer value greater than to display the multiple months in the datepicker.

下面的示例演示在一个日期选择器中包含多个月的日期选择器。 我们可以将numberOfMonths选项设置为一个大于显示日期选择器中多个月份的整数值。

datepicker-multiple.html

datepicker-multiple.html

<!doctype html>
<html>
<head>
  <title>jQuery UI Datepicker – Multiple Months</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/ui-darkness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>

  <script>
  $(function() {
    $( "#date_picker" ).datepicker({
      numberOfMonths: 2
    });
  });
  </script>
</head>
<body>
 
<p>Click Here To Enter the Date: <input type="text" id="date_picker"></p>
 
</body>
</html>

You will see the following output on your browser.

datepicker-multiple

您将在浏览器中看到以下输出。

You can see all these HTML pages in action by visiting to below URL.

您可以通过访问以下URL来查看所有这些HTML页面的运行情况。

jQueryUI Datepicker Plugin Demos

jQueryUI Datepicker插件演示

That’s all for the jQueryUI Datepicker plugin. You will see more jQuery plugins in the coming posts.

jQueryUI Datepicker插件就这些了。 在接下来的文章中,您将看到更多的jQuery插件。

翻译自: https://www.journaldev.com/5514/jqueryui-datepicker-plugin-calendar-options

jqueryui时间插件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值