JQuery datepicker 用法 1

轉自http://fateful.i.sohu.com/blog/view/189897336.htm


jQuery UI很強大,其中的日期選擇插件Datepicker是一個配置靈活的插件,我們可以自定義其展示方式,包括日期格式、語言、限制選擇日期範圍、添加相關按鈕以及其它導航等。
官方地址:http://docs.jquery.com/UI/Datepicker,官方示例: http://jqueryui.com/demos/datepicker/

一個不錯的地址,用來DIY jQuery UI界面效果的站點http://jqueryui.com/themeroller/

DatePicker基本使用方法:

 

<!DOCTYPE html>
<html>
<head>
  
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

  
<script>
  $(document).ready(
function() {
    $(
"#datepicker").datepicker();
  });
  
</script>
</head>
<body style="font-size:62.5%;">

<div type="text" id="datepicker"></div>

</body>
</html>
page up/down - 上一月、下一月
ctrl+page up/down - 上一年、下一年
ctrl+home - 當前月或最後一次打開的日期
ctrl+left/right - 上一天、下一天
ctrl+up/down - 上一週、下一週
enter - 確定選擇日期
ctrl+end - 關閉並清除已選擇的日期
escape - 關閉並取消選擇
$.datepicker.setDefaults( settings ) - 全局設置日期選擇插件的參數.
$.datepicker.formatDate( format
, date, settings ) - 格式化顯示的日期字符串
$.datepicker.iso8601Week( date ) - 給出一個日期,確實他是一年中的第幾周
$.datepicker.parseDate( format
, value, settings ) - 按照指定格式獲取日期字符串
d - 每月的第幾天 (沒有前導零)
dd - 每月的第幾天 (兩位數字)
o - 一年中的第幾天 (沒有前導零)
oo - 一年中的第幾天 (三位數字)
D - day name short
DD - day name long
m - 月份 (沒有前導零)
mm - 月份 (兩位數字)
M - month name short
MM - month name long
y - 年份 (兩位數字)
yy - 年份 (四位數字)
@ - Unix 時間戳 (從 
01/01/1970 開始)
'...' - 文本
'' - 單引號
(其它) - 文本
ATOM - 'yy-mm-dd' (Same as RFC 3339/ISO 8601)
COOKIE - 'D
, dd M yy'
ISO_8601 - 'yy-mm-dd'
RFC_822 - 'D
, d M y'
RFC_850 - 'DD
, dd-M-y'
RFC_1036 - 'D
, d M y
RFC_1123 - 'D
, d M yy'
RFC_2822 - 'D
, d M yy'
RSS - 'D
, d M y'
TIMESTAMP - '@'
W3C - 'yy-mm-dd'

 

altField : String : ''
  將選擇的日期同步到另一個域中,配合altFormat可以顯示不同格式的日期字符串。
  初始:$('.selector').datepicker({ altField: '#actualDate' })
;
  獲取:var altField = $('.selector').datepicker('option', 'altField');
  設置:$('.selector').datepicker('option', 'altField', '#actualDate');  

altFormat : String : ''
  當設置了altField的情況下,顯示在另一個域中的日期格式。
  初始:$('.selector').datepicker({ altFormat: 'yy-mm-dd' })
;
  獲取:var altFormat = $('.selector').datepicker('option', 'altFormat');
  設置:$('.selector').datepicker('option', 'altFormat', 'yy-mm-dd');  

appendText : String : ''
  在日期插件的所屬域後面添加指定的字符串。
  初始:$('.selector').datepicker({ appendText: '(yyyy-mm-dd)' })
;
  獲取:var appendText = $('.selector').datepicker('option', 'appendText');
  設置:$('.selector').datepicker('option', 'appendText', '(yyyy-mm-dd)');  

buttonImage : String : ''
  設置彈出按鈕的圖片,如果非空,則按鈕的文本將成爲alt屬性,不直接顯示。
  初始:$('.selector').datepicker({ buttonImage: '/images/datepicker.gif' })
;
  獲取:var buttonImage = $('.selector').datepicker('option', 'buttonImage');
  設置:$('.selector').datepicker('option', 'buttonImage', '/images/datepicker.gif');  

buttonImageOnly : Boolean : false
  Set to true to place an image after the field to use as the trigger without it appearing on a button.
  初始:$('.selector').datepicker({ buttonImageOnly: true })
;
  獲取:var buttonImageOnly = $('.selector').datepicker('option', 'buttonImageOnly');
  設置:$('.selector').datepicker('option', 'buttonImageOnly', true);  

buttonText : String : '...'
  設置觸發按鈕的文本內容。
  初始:$('.selector').datepicker({ buttonText: 'Choose' })
;
  獲取:var buttonText = $('.selector').datepicker('option', 'buttonText');
  設置:$('.selector').datepicker('option', 'buttonText', 'Choose');  

changeMonth : Boolean : false
  設置允許通過下拉框列表選取月份。
  初始:$('.selector').datepicker({ changeMonth: true })
;
  獲取:var changeMonth = $('.selector').datepicker('option', 'changeMonth');
  設置:$('.selector').datepicker('option', 'changeMonth', true);  

changeYear : Boolean : false
  設置允許通過下拉框列表選取年份。
  初始:$('.selector').datepicker({ changeYear: true })
;
  獲取:var changeYear = $('.selector').datepicker('option', 'changeYear');
  設置:$('.selector').datepicker('option', 'changeYear', true);  

closeTextType: StringDefault: 'Done'
  設置關閉按鈕的文本內容,此按鈕需要通過showButtonPanel參數的設置才顯示。
  初始:$('.selector').datepicker({ closeText: 'X' })
;
  獲取:var closeText = $('.selector').datepicker('option', 'closeText');
  設置:$('.selector').datepicker('option', 'closeText', 'X');  

constrainInput : Boolean : true
  如果設置爲true,則約束當前輸入的日期格式。
  初始:$('.selector').datepicker({ constrainInput: false })
;
  獲取:var constrainInput = $('.selector').datepicker('option', 'constrainInput');
  設置:$('.selector').datepicker('option', 'constrainInput', false);  

currentText : String : 'Today'
  設置當天按鈕的文本內容,此按鈕需要通過showButtonPanel參數的設置才顯示。
  初始:$('.selector').datepicker({ currentText: 'Now' })
;
  獲取:var currentText = $('.selector').datepicker('option', 'currentText');
  設置:$('.selector').datepicker('option', 'currentText', 'Now');  

dateFormat : String : 'mm/dd/yy'
  設置日期字符串的顯示格式。
  初始:$('.selector').datepicker({ dateFormat: 'yy-mm-dd' })
;
  獲取:var dateFormat = $('.selector').datepicker('option', 'dateFormat');
  設置:$('.selector').datepicker('option', 'dateFormat', 'yy-mm-dd');  

dayNames : Array : 
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
  設置一星期中每天的名稱,從星期天開始。此內容用於dateFormat時顯示,以及日曆中當鼠標移至行頭時顯示。
  初始:$('.selector').datepicker({ dayNames: 
['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'] });
  獲取:var dayNames = $('.selector').datepicker('option', 'dayNames');
  設置:$('.selector').datepicker('option', 'dayNames', ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi']);  

dayNamesMin : Array : 
['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
  設置一星期中每天的縮語,從星期天開始,此內容用於dateFormat時顯示,以前日曆中的行頭顯示。
  初始:$('.selector').datepicker({ dayNamesMin: 
['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'] });
  獲取:var dayNamesMin = $('.selector').datepicker('option', 'dayNamesMin');
  設置:$('.selector').datepicker('option', 'dayNamesMin', ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa']);

發佈了12 篇原創文章 · 獲贊 3 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章