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

淺談如何實(shí)現(xiàn)easyui的datebox格式化

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

看了網(wǎng)上有很多的解決方法,我也寫一個(gè)比較簡(jiǎn)單方法。實(shí)現(xiàn)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){//當(dāng)月份不滿10的時(shí)候前面補(bǔ)0,例如09
 months='0'+months;
 }
 
 if(dates<10){//當(dāng)日期不滿10的時(shí)候前面補(bǔ)0,例如09
 dates='0'+dates;
 }
 return years+"++"+months+"++"+dates;//根據(jù)自己需求進(jìn)行改動(dòng)
 }
 });

補(bǔ)充:

DateBox 日期顯示默認(rèn)的格式為“dd/mm/yyyy”,如果想自定義成我們的格式需要實(shí)現(xiàn)兩個(gè)函數(shù),formatter和parser。
formatter函數(shù)使得選擇日期后將其格式化為我們需要的格式,parser函數(shù)在選擇好日期后告訴控件如何去解析我們自定義的格式。
定義如下:
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格式化最簡(jiǎn)單方法,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評(píng)論