惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
Cloudbric
Cloudbric
月光博客
月光博客
I
InfoQ
Recorded Future
Recorded Future
K
Kaspersky official blog
T
Tor Project blog
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hacker News - Newest:
Hacker News - Newest: "LLM"
G
Google Developers Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
GbyAI
GbyAI
Martin Fowler
Martin Fowler
S
Schneier on Security
D
Docker
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Cyberwarzone
Cyberwarzone
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 叶小钗
C
Cisco Blogs
The GitHub Blog
The GitHub Blog
S
Securelist
Vercel News
Vercel News
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
T
Tenable Blog
Engineering at Meta
Engineering at Meta
G
GRAHAM CLULEY
N
News and Events Feed by Topic
S
Security @ Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
C
Check Point Blog
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - N/A2011

Managing Hierarchical Data in MySQL php soapclient with wsse 转贴 MySQL Multiple Result Procs in PHP 转贴 Using MySQL Stored Procedures with PHP mysql/mysqli/pdo php generate pdf open office (java) ant + emma + junit Copy all files recursively from one folder to another RecursiveFileFinder 转贴: 怎样找第一份工作 PerformanceCounter in .net Trace in .net Logger in .net 转贴: 傅立叶级数(Fourier Series) 推导 CAS in .net Encrypting and Decrypting in .net Access Control List in .net User and Data Security in .net Unmanaged code in .net
转贴 jQuery Datepicker by Example
N/A2011 · 2010-05-05 · via 博客园 - N/A2011

转自:http://hackingon.net/post/jQuery-Datepicker-by-Example.aspx

I have been working almost exclusively with Asp.Net MVC for the last twelve months. Working with MVC has encouraged me to move more towards client side, javascript based controls, like the jQuery datepicker. The jQuery datepicker is part of the jQuery UI library. The jQuery UI library is a collection of widgets, effects, interactions and theming support.

This post will cover, by example, some of the basic datepicker usages. Once you have these covered the jQuery datepicker is a flexible, powerful component. If you download the full source, included at the end of this post, you will see that the examples are formatted with a css file (ui.all.css) and some images. This look and feel was generated using the online jquery themeroller tool.

Always Visible Datepicker Calendar

This example has a datepicker always visible and available for selecting a date.

View the Example

and here is the code:

01.<html>

02.<head><title>jQuery Open Calendar</title>

03.<link rel="stylesheet" href="ui.all.css" type="text/css" media="screen" />

04. 

05.</head>

06.<body>

07.<form>

08.    <input id="date" type="textbox"/>

09.    <div id="calendar"/>

10.</form>

11. 

14.    <script type="text/javascript">

15.        $(document).ready(function(){

16.                $("div#calendar").datepicker({ altField: 'input#date', altFormat: 'yy-mm-dd' });

17.        });

18.    </script>

19. 

20.</body>

21.</html>

Notice that I am loading the required jQuery javascript files from google. This has some minor performance advantages but you could just as easily keep the files locally. The datepicker is initialized using the jQuery ready function, which runs when the page has loaded. The datepicker is built on an empty div and in this example it simply updates a textbox with the selected date. If you don't want to see the textbox you can use a hidden input element instead.

jQuery datepicker opens on a button click

In this example the datepicker is invisible until a form button is clicked. The datepicker disappears again once a date is selected.

View the Example

and here is the code:

01.<html>

02.<head><title>jQuery Open on button</title>

03.<link rel="stylesheet" href="ui.all.css" type="text/css" media="screen" />

04. 

05.</head>

06.<body>

07.<form>

08.    <input id="date" type="textbox"/>

09.</form>

10. 

13.    <script type="text/javascript">

14.        $(document).ready(function(){

15.                $("#date").datepicker({ showOn: 'button', buttonText: "select" });

16.        });

17.    </script>

18. 

19.</body>

20.</html>

For this example the empty div is not required. The datepicker is constructed on the textbox. Again, a hidden input also works.

jQuery datepicker opens on an image click

This time the datepicker is triggered by clicking on an image. Other than that it is almost identical to the previous example.

View the Example

and here is the code:

01.<html>

02.<head><title>jQuery Open on image button</title>

03.<link rel="stylesheet" href="ui.all.css" type="text/css" media="screen" />

04. 

05.</head>

06.<body>

07.<form>

08.    <input id="date" type="textbox"/>

09.</form>

10. 

13.    <script type="text/javascript">

14.        $(document).ready(function(){

15.                $("#date").datepicker({ showOn: 'button', buttonImageOnly: true, buttonImage: 'images/icon_cal.png' });

16.        });

17.    </script>

18.</body>

19.</html>

jQuery datepicker selecting a date range

It is common to allow the user to select a range of dates. This last example supports range selection by allowing the user to click once to select the start of the range, and once more to select the end of the range.

View the Example

and here is the code:

01.<html>

02.<head><title>jQuery date range selector</title>

03.<link rel="stylesheet" href="ui.all.css" type="text/css" media="screen" />

04. 

05.</head>

06.<body>

07.<form>

08.    <input id="Range" type="textbox" value="09-04-06"/>

09.    <div id="fromCalendar"></div>

10.</form>

11. 

14.    <script type="text/javascript">

15.        $(document).ready(function(){

16.                $("#fromCalendar").datepicker({ altField: "#Range", altFormat: 'yy-mm-dd', rangeSelect: true });

17.        });

18.    </script>

19.</body>

20.</html>

The caveat with this last example is that you will need some sort of post-processing step to separate the start and finish dates of the range. Typically the date will arrive on the server in a format such as "2009-04-10 - 2009-05-27".

To run these examples locally, with the full look and feel, you can download a zip containing everything.