juqery easyui-datebox 日期选择框日期格式化formatter

jquery | 2019-09-13 10:02:39

平时习惯了这样的日期格式2017-04-28,但easyui-datebox偏不是这种格式。那就要用formatter方法了。
案例代码:

<input class="easyui-datebox" name="startDate" id="startDate" data-options="value:new Date(new Date().getTime()-1000*60*60*24*30),formatter:function(date){  
                                  var y = date.getFullYear();  
                                  var m = date.getMonth()+1;  
                                  var d = date.getDate(); 
                                  function formatNumber(value){  
                                   return (value < 10 ? '0' : '') + value;  
                                  }  
                                 
                                  return y+'-'+formatNumber(m)+'-'+formatNumber(d);  
                                 },  
                                 parser:function(s){  
                                  var t = Date.parse(s);  
                                  if (!isNaN(t)){  
                                   return new Date(t);  
                                  } else {  
                                   return new Date();  
                                  }  
                                 }  " style="width:120px">


formatter和parser这两个都需要。juqery easyui-datebox 日期选择框日期格式化formatter就是这样简单,直接复制代码过去用就可以了。

登录后即可回复 登录 | 注册
    
关注编程学问公众号