Home Web Front-end JS Tutorial Usage of jquery UI Datepicker time control (2)

Usage of jquery UI Datepicker time control (2)

May 28, 2021 pm 03:54 PM
jquery ui

This article continues to introduce how to use the jquery UI Datepicker time control, mainly about the introduction and use of the Datepicker plug-in, and shares the first usage example of the calendar plug-in, which has certain reference value. Friends in need can For reference, I hope it will be helpful to everyone.

Usage of jquery UI Datepicker time control (2)

Let’s first take a look at the property table of the Datepicker plug-in:

Usage of jquery UI Datepicker time control (2)

Usage of jquery UI Datepicker time control (2)

Usage of jquery UI Datepicker time control (2)

Usage of jquery UI Datepicker time control (2)

##The first usage example of the calendar plug-in

First import the required class library files :

<</SPAN>scripttype="text/javascript" ></</SPAN>script>
<</SPAN>scripttype="text/javascript" src="${pageContext.request.contextPath }/js/jquery.ui.datepicker-zh-CN.js"></</SPAN>script>
<</SPAN>scripttype="text/javascript"src="${pageContext.request.contextPath }/js/jquery-ui-1.8.18.custom.min.js"></</SPAN>script>
<</SPAN>linkrel="stylesheet"type="text/css"href="${pageContext.request.contextPath }/css/ui-lightness/jquery-ui-1.8.18.custom.css">
Copy after login

First write the page code:

<</SPAN>p class="demo">
<</SPAN>p>Date:<</SPAN>input type="text" id="datepicker"></</SPAN>p>
</</SPAN>p>
Copy after login

Usage of jquery UI Datepicker time control (2)

Then use the js code to call the plug-in


Screenshot of the effect :

Usage of jquery UI Datepicker time control (2)

The following is to verify some common attributes through examples:

1, altField:Use the alternate output field, which is about to be selected The date is output to another control in another format, and the value is the selector, that is, the control to be output

altFormat: format of altField output

Instance verification:

Page code:

<</SPAN>p class="demo">
<</SPAN>p>Date: <</SPAN>input type="text" id="datepicker">
<</SPAN>input type="text" id="alternate" size="30"/></</SPAN>p>
</</SPAN>p>
Copy after login

Usage of jquery UI Datepicker time control (2)

##Js code:

$(function() {
$( "#datepicker" ).datepicker({
altField: "#alternate",
altFormat: "DD, d MM, yy"
});
});
Copy after login
Effect screenshot:

Usage of jquery UI Datepicker time control (2)

2. showAnim:

Set the animation name for displaying or hiding the date panel Writing of js code:

$(function() {
$( "#datepicker" ).datepicker();
$( "#anim" ).change(function() {
$( "#datepicker" ).datepicker( "option", "showAnim", $( this ).val() );
});
});
Copy after login

3. showButtonPanel:

Whether Display button panelJs code:

$( "#datepicker" ).datepicker({
showButtonPanel:true
});
Copy after login

As shown in the picture, you can see that there are two buttons below the panel: clicking "Today" will jump to today's date, clicking "Close" will jump to today's date. Close the panel.

Usage of jquery UI Datepicker time control (2)

4. dateFormat:

Specify the format for displaying the date Js code:

$( "#datepicker" ).datepicker({
dateFormat:"yy/mm/dd"
});
Copy after login

Effect screenshot:

Usage of jquery UI Datepicker time control (2)As you can see from the image, the date format in the text box has changed from "yy-mm-dd" to "by/mm/dd". Of course, there are other formats that can be set according to your own preferences.

5. changeMonth:
Whether to use the drop-down list to select the monthchangeYear: whether to use the drop-down list to select the yearAdd this attribute in the js code: changeMonth:true or changeYear:true
The month or year in the title bar will appear in the form of a drop-down menu:

Usage of jquery UI Datepicker time control (2)

6. yearRange:

Set the year range displayed in the drop-down list box. It can be relative to this year (-nn: nn) or relative to the selected year (c-nn:c nn) or absolute year (nnnn:nnnn) Add attributes in the js code:

$( "#datepicker" ).datepicker({
changeYear: true,
yearRange:"2011:2012"
});
Copy after login

Effect Screenshot:

Usage of jquery UI Datepicker time control (2) From the picture, you can see that the position of the year is in the form of a drop-down menu, in which only the options for 2011 and 2012 will appear in the drop-down menu.

Note: The yearRange attribute is only used when changeYear is true.



7. numberOfMonths:

Set how many months to display at a time. It can be an array containing two numbers, indicating the number of rows and columns displayed Js code:

$( "#datepicker" ).datepicker({
numberOfMonths: 3
});
Copy after login

Specify numberOfMonths as 3 above, then the pop-up calendar panel will display the current and next two months , as shown in the picture:

8、showOn:设置触发选择器的事件名称
buttonText:指定触发按钮上显示的文本,showOn属性应设置为button或both
buttonImage:指定弹出按钮图像的URL,若设置则buttonText将成为alt值
buttonImageOnly:是否将图像放在控件后面,作为触发器,如果设置为true那么按钮将只剩下图片作为按钮,是页面更加美观
这里我编写三个文本框进行以上属性的对比:
1) Js代码:

$( "#datepicker2" ).datepicker({
showOn: "both",
buttonText:"日历按钮"
});
Copy after login

效果截图:

Usage of jquery UI Datepicker time control (2)

2)将按钮设置为图片:
Js代码:

$( "#datepicker" ).datepicker({
showOn: "button",
buttonImage: "images/calendar.gif",
buttonImageOnly: true
});
Copy after login

1Usage of jquery UI Datepicker time control (2)

通过以上对比,可以理解buttonImageOnly属性的作用。
9、minDate:可以选择的最小日期,null表示无限制
maxDate:可以选择的最大日期。null表示无限制
两者都是根据以当天日期为基础的。
Js代码:

$(function() {
$( "#datepicker" ).datepicker({
//表示以当天为准,只有在20天之前和10天之后的日期之间的时间可以选择
minDate: -20,
maxDate: "+10D"
});
});
Copy after login

如下图在7号之前都不可选择(当前日期为27):

1Usage of jquery UI Datepicker time control (2)

以上就是对jquery UI Datepicker时间控件的使用方法深入学习,为之后的学习打下了基础,希望大家继续关注jquery UI Datepicker时间控件终结篇学习。

相关推荐:

jquery UI Datepicker时间控件的用法(一)

jquery UI Datepicker时间控件的用法(三)

相关视频教程推荐:jQuery教程(视频)

The above is the detailed content of Usage of jquery UI Datepicker time control (2). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

How to implement panel drag and drop adjustment function similar to VSCode in front-end development? How to implement panel drag and drop adjustment function similar to VSCode in front-end development? Apr 04, 2025 pm 02:06 PM

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...

See all articles