格式化日期
可以通过日期格式重新定义Datepicker显示日期时的格式。
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 > |
11 |
$("#datepicker").datepicker(); |
12 |
$("#format").change(function () { |
13 |
$("#datepicker").datepicker("option", |
14 |
"dateFormat", $(this).val()); |
22 |
< input type = "text" id = "datepicker" size = "30" /></ p > |
26 |
< option value = "mm/dd/yy" >Default - mm/dd/yy</ option > |
27 |
< option value = "yy-mm-dd" >ISO 8601 - yy-mm-dd</ option > |
28 |
< option value = "d M, y" >Short - d M, y</ option > |
29 |
< option value = "d MM, y" >Medium - d MM, y</ option > |
30 |
< option value = "DD, d MM, yy" >Full - DD, d MM, yy</ option > |
31 |
< option value = "'day' d 'of' MM 'in the year' yy" > |
32 |
With text - 'day' d 'of' MM 'in the year' yy |

本地化支持
Datepicker缺省使用英语显示,可以通过配置修改显示语言。
如果需要支持不同语言,可以添加,如:
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 src = "scripts/jquery.ui.datepicker-ar.js" ></ script > |
10 |
< script src = "scripts/jquery.ui.datepicker-fr.js" ></ script > |
11 |
< script src = "scripts/jquery.ui.datepicker-he.js" ></ script > |
12 |
< script src = "scripts/jquery.ui.datepicker-zh-TW.js" ></ script > |
16 |
$.datepicker.setDefaults($.datepicker.regional[""]); |
17 |
$("#datepicker").datepicker($.datepicker.regional["fr"]); |
18 |
$("#locale").change(function () { |
19 |
$("#datepicker").datepicker("option", |
20 |
$.datepicker.regional[$(this).val()]); |
28 |
< input type = "text" id = "datepicker" /> |
30 |
< option value = "ar" >Arabic ((لعربي</ option > |
31 |
< option value = "zh-TW" >Chinese Traditional (繁體中文)</ option > |
32 |
< option value = "fr" selected = "selected" >French (Français)</ option > |
33 |
< option value = "he" >Hebrew ((עברית</ option > |

如果需要添加自定义的语言,比如简体中文,可以打开jquery.ui.datepicker-zh-TW.js 看看,
4 |
$.datepicker.regional[ 'zh-TW' ] = { |
9 |
monthNames: [ '一月' , '二月' , '三月' , '四月' , '五月' , '六月' , |
10 |
'七月' , '八月' , '九月' , '十月' , '十一月' , '十二月' ], |
11 |
monthNamesShort: [ '一月' , '二月' , '三月' , '四月' , '五月' , '六月' , |
12 |
'七月' , '八月' , '九月' , '十月' , '十一月' , '十二月' ], |
13 |
dayNames: [ '星期日' , '星期一' , '星期二' , '星期三' , '星期四' , '星期五' , '星期六' ], |
14 |
dayNamesShort: [ '周日' , '周一' , '周二' , '周三' , '周四' , '周五' , '周六' ], |
15 |
dayNamesMin: [ '日' , '一' , '二' , '三' , '四' , '五' , '六' ], |
17 |
dateFormat: 'yy/mm/dd' , |
20 |
showMonthAfterYear: true , |
22 |
$.datepicker.setDefaults($.datepicker.regional[ 'zh-TW' ]); |
只要把zh-TW 改成 zh-CN ,把其中的繁体“關閉”改成“关闭” 保存为 jquery.ui.datepicker-zh-CN.js,然后使用 zh-CN 作为区域选项即可。