jquery-ui-datepicker – 将jquery datepicker dateFormat替换为momentjs解析和格式化

为了保持一致性,我希望能够切换JQuery UI的datepicker的解析/格式化.有什么想法可能是最好的方法呢?

解决方法

到目前为止,我发现最好的方法是覆盖全局jquery-ui parseDate和formatDate函数,如下所示:
$.datepicker.parseDate = function(format,value) {
    return moment(value,format).toDate();
};
$.datepicker.formatDate = function (format,value) {
    return moment(value).format(format);
};

那么这很好地允许你使用通常的语法来附加一个datepicker到一个字段,但你指定的格式将改为引用一个momentjs格式而不是http://momentjs.com/docs/#/parsing/string-format/

$(".selector").datepicker({ dateFormat: "MM-DD-YYYY" });

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...