欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淺談如何實現easyui的datebox格式化

 更新時間:2016年06月12日 11:30:10   作者:海潛  
這篇文章主要和大家一起聊一聊如何實現easyui的datebox格式化的方法,感興趣的小伙伴們可以參考一下

看了網上有很多的解決方法,我也寫一個比較簡單方法。實現easyui的datebox格式化。效果如下,用“++”隔開,看你喜歡用什么都可以。

 

1、html

<span class="span1">證件有效期至:</span> 
<span><input id="passvali" name="hotel.passvali"></span> 

2、js

/* 證件有效期至 */
 $('#passvali').datebox({
 formatter: function(date){ 
 var years=date.getFullYear();//獲取年
 var months=date.getMonth()+1;//獲取日
 var dates=date.getDate();//獲取月
 
 if(months<10){//當月份不滿10的時候前面補0,例如09
 months='0'+months;
 }
 
 if(dates<10){//當日期不滿10的時候前面補0,例如09
 dates='0'+dates;
 }
 return years+"++"+months+"++"+dates;//根據自己需求進行改動
 }
 });

補充:

DateBox 日期顯示默認的格式為“dd/mm/yyyy”,如果想自定義成我們的格式需要實現兩個函數,formatter和parser。
formatter函數使得選擇日期后將其格式化為我們需要的格式,parser函數在選擇好日期后告訴控件如何去解析我們自定義的格式。
定義如下:
formatter:A function to format the date, the function take a 'date' parameter and return a string value.
parser:A function to parse a date string, the function take a 'date' string and return a date value.
如將日期格式化為yyyy-mm-dd的格式:

$('#dd1').datebox({
 formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();},
 parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/")));}
});

以上就是為大家分享的easyui的datebox格式化最簡單方法,希望對大家的學習有所幫助。

相關文章

最新評論