原文地址为:
jQuery EasyUI中的日期控件DateBox修改
转载请注明本文地址: jQuery EasyUI中的日期控件DateBox修改
jQuery EasyUI中的日期控件DateBox很好用的,首先需要引入jquery文件,代码如下:
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8"> <title>Basic DateBox - jQuery EasyUI Demo</title>
5 <link rel="stylesheet" type="text/css" href="css/easyui.css">
6 <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
7 <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
8 </head>
9 <body>
10 <div> <input class="easyui-datebox"></input> </div>
11 </body>
12 </html>
效果为:
这里是英文的,如果有要求用中文的,那么需要的改的几个地方,首先是月份的,找到下面的代码:
1 $.fn.calendar.parseOptions=function(_454){
2 var t=$(_454);
3 return $.extend({},$.parser.parseOptions(_454,["width","height",{firstDay:"number",fit:"boolean",border:"boolean"}]));
4 };
5 $.fn.calendar.defaults={width:180,height:180,fit:false,border:true,firstDay:0,weeks:["S","M","T","W","T","F","S"],months:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],year:new Date().getFullYear(),month:new Date().getMonth()+1,current:new Date(),onSelect:function(date){
6 }};
7 })(jQuery);
改成下面的对应的
1 $.fn.calendar.parseOptions=function(_454){
2 var t=$(_454);
3 return $.extend({},$.parser.parseOptions(_454,["width","height",{firstDay:"number",fit:"boolean",border:"boolean"}]));
4 };
5 $.fn.calendar.defaults={width:180,height:180,fit:false,border:true,firstDay:0,weeks:["一", "二", "三", "四", "五", "六", "日"], months:["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], year:new Date().getFullYear(),month:new Date().getMonth()+1,current:new Date(),onSelect:function(date){
6 }};
7 })(jQuery);
这样就行了,还有一个时间格式的修改,默认的是5/27/2013,即月/日/年的格式,如果换成的2013-05-27这样的,官方也给出了代码,如下:
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8">
5 <title>Basic DateBox - jQuery EasyUI Demo</title>
6 <link rel="stylesheet" type="text/css" href="css/easyui.css">
7 <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
8 <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
9 </head>
10 <body>
11 <div class="date">
12 <input class="easyui-datebox" data-options="formatter:myformatter,parser:myparser"></input>
13 </div>
14 </body>
15 <script type="text/javascript">
16 function myformatter(date){
17 var y = date.getFullYear();
18 var m = date.getMonth()+1;
19 var d = date.getDate();
20 return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
21 }
22 function myparser(s){
23 if (!s) return new Date();
24 var ss = (s.split('-'));
25 var y = parseInt(ss[0],10);
26 var m = parseInt(ss[1],10);
27 var d = parseInt(ss[2],10);
28 if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
29 return new Date(y,m-1,d);
30 }else{
31 return new Date();
32 }
33 }
34 </script>
35 </html>
这样的话,格式怎么变的话,都很好修改的!
转载请注明本文地址: jQuery EasyUI中的日期控件DateBox修改