日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

转贴 jQuery Datepicker by Example

發布時間:2025/3/13 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 转贴 jQuery Datepicker by Example 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉自: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:

view sourceprint?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.?12.????<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> 13.????<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>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 also includes powerful ajax features for enriching the experience of a web application.

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:

view sourceprint?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.?11.????<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> 12.????<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>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:

view sourceprint?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.?11.????<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> 12.????<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>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:

view sourceprint?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.?12.????<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> 13.????<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>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.

?

轉載于:https://www.cnblogs.com/aspxphpjsprb/archive/2010/05/05/1727625.html

總結

以上是生活随笔為你收集整理的转贴 jQuery Datepicker by Example的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。