jQuery 入門教程(32): jQuery UI Datepicker 樣本(五)

來源:互聯網
上載者:User

設定可以選擇的日期範圍
有時希望使用者在給定的日期內選擇,比如預約會議的時間,只能在當天開始的一個月帶10天以內。這時可以通過配置minDate和maxDate 來設定,如果minDate或maxDate 沒有配置,表示沒有最小日期或最大日期的限制。

1 <!doctype html>

2 <html lang="en">

3 <head>

4     <meta charset="utf-8" />

5     <title>jQuery UI Demos</title>

6     <link rel="stylesheet" href="themes/trontastic/jquery-ui.css" />

7     <script src="scripts/jquery-1.9.1.js"></script>

8     <script src="scripts/jquery-ui-1.10.1.custom.js"></script>

9    <script>

10        $(function () {

11            $("#datepicker").datepicker({

12                minDate: 0,

13                maxDate: "+1M +10D"

14            });

15        });

16   </script>

17 </head>

18 <body>

19   

20 <p>Date: <input type="text" id="datepicker" /></p>

21   

22 </body>

23 </html>

 

可以看到小於當天的日期變灰且無法選擇。

設定日期範圍

可以使用兩個DatePicker配合使用,使用者可以選擇一個開始日期和一個終止日期。

1 <!doctype html>

2 <html lang="en">

3 <head>

4     <meta charset="utf-8" />

5     <title>jQuery UI Demos</title>

6     <link rel="stylesheet" href="themes/trontastic/jquery-ui.css" />

7     <script src="scripts/jquery-1.9.1.js"></script>

8     <script src="scripts/jquery-ui-1.10.1.custom.js"></script>

9     <script>

10         $(function () {

11             $("#from").datepicker({

12                 defaultDate: "+1w",

13                 changeMonth: true,

14                 numberOfMonths: 3,

15                 onClose: function (selectedDate) {

16                     $("#to").datepicker("option", "minDate", selectedDate);

17                 }

18             });

19             $("#to").datepicker({

20                 defaultDate: "+1w",

21                 changeMonth: true,

22                 numberOfMonths: 3,

23                 onClose: function (selectedDate) {

24                     $("#from").datepicker("option", "maxDate", selectedDate);

25                 }

26             });

27         });

28     </script>

29 </head>

30 <body>

31  

32     <label for="from">From</label>

33     <input type="text" id="from" name="from" />

34     <label for="to">to</label>

35     <input type="text" id="to" name="to" />

36  

37 </body>

38 </html>

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.