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.
Let’s first take a look at the property table of the Datepicker plug-in:
##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">First write the page code:
<</SPAN>p class="demo"> <</SPAN>p>Date:<</SPAN>input type="text" id="datepicker"></</SPAN>p> </</SPAN>p>
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 outputInstance 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>
$(function() {
$( "#datepicker" ).datepicker({
altField: "#alternate",
altFormat: "DD, d MM, yy"
});
});
Effect screenshot:
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() ); }); });
3. showButtonPanel:
Whether Display button panelJs code:
$( "#datepicker" ).datepicker({ showButtonPanel:true });
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.
Specify the format for displaying the date Js code:
$( "#datepicker" ).datepicker({ dateFormat:"yy/mm/dd" });
Effect screenshot:
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:
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" });
Effect Screenshot:
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.
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 });
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:"日历按钮" });
效果截图:
2)将按钮设置为图片:
Js代码:
$( "#datepicker" ).datepicker({ showOn: "button", buttonImage: "images/calendar.gif", buttonImageOnly: true });
通过以上对比,可以理解buttonImageOnly属性的作用。
9、minDate:可以选择的最小日期,null表示无限制
maxDate:可以选择的最大日期。null表示无限制
两者都是根据以当天日期为基础的。
Js代码:
$(function() { $( "#datepicker" ).datepicker({ //表示以当天为准,只有在20天之前和10天之后的日期之间的时间可以选择 minDate: -20, maxDate: "+10D" }); });
如下图在7号之前都不可选择(当前日期为27):
以上就是对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!

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

10 fun jQuery game plugins to make your website more attractive and enhance user stickiness! While Flash is still the best software for developing casual web games, jQuery can also create surprising effects, and while not comparable to pure action Flash games, in some cases you can also have unexpected fun in your browser. jQuery tic toe game The "Hello world" of game programming now has a jQuery version. Source code jQuery Crazy Word Composition Game This is a fill-in-the-blank game, and it can produce some weird results due to not knowing the context of the word. Source code jQuery mine sweeping game

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

This tutorial demonstrates how to create a captivating parallax background effect using jQuery. We'll build a header banner with layered images that create a stunning visual depth. The updated plugin works with jQuery 1.6.4 and later. Download the

Matter.js is a 2D rigid body physics engine written in JavaScript. This library can help you easily simulate 2D physics in your browser. It provides many features, such as the ability to create rigid bodies and assign physical properties such as mass, area, or density. You can also simulate different types of collisions and forces, such as gravity friction. Matter.js supports all mainstream browsers. Additionally, it is suitable for mobile devices as it detects touches and is responsive. All of these features make it worth your time to learn how to use the engine, as this makes it easy to create a physics-based 2D game or simulation. In this tutorial, I will cover the basics of this library, including its installation and usage, and provide a

This article demonstrates how to automatically refresh a div's content every 5 seconds using jQuery and AJAX. The example fetches and displays the latest blog posts from an RSS feed, along with the last refresh timestamp. A loading image is optiona

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.