From 53187989d6308987cf2b810ef5ea9b08b19dae80 Mon Sep 17 00:00:00 2001 From: yangxiongwei Date: Mon, 11 Apr 2016 11:35:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=B6=E5=88=86=E7=A7=92?= =?UTF-8?q?=E5=9C=A8=E5=89=8D=E6=A0=BC=E5=BC=8F=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E6=97=A5=E5=8E=86=E5=88=9D=E5=A7=8B=E5=8C=96=E9=94=99=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- laydate.dev.js | 57 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/laydate.dev.js b/laydate.dev.js index 8385736..8f95091 100755 --- a/laydate.dev.js +++ b/laydate.dev.js @@ -392,12 +392,12 @@ Dates.viewDate = function(Y, M, D){ getCheck = null }); Dates.addClass(as.mms[Dates.ymd[1]], as[2]); - + //定位时分秒 log.times = [ - Dates.inymd[3]|0 || 0, - Dates.inymd[4]|0 || 0, - Dates.inymd[5]|0 || 0 + Dates.inymd[Dates.elemIndexMap.hour]|0 || 0, + Dates.inymd[Dates.elemIndexMap.minute]|0 || 0, + Dates.inymd[Dates.elemIndexMap.second]|0 || 0 ]; Dates.each(new Array(3), function(i){ Dates.hmsin[i].value = Dates.digit(Dates.timeVoid(log.times[i], i) ? Dates.mins[i+3]|0 : log.times[i]|0); @@ -460,10 +460,34 @@ Dates.viewYears = function(YY){ }); }; +Dates.getEachElementIndex = function(format) { + var components = {}; + var currentIndex = 0; + format.replace(/YYYY|MM|DD|hh|mm|ss/g, function(str, index){ + if (str === 'YYYY') { + components['year'] = currentIndex++; + } else if (str === 'MM') { + components['month'] = currentIndex++; + } else if (str === 'DD') { + components['day'] = currentIndex++; + } else if (str === 'hh') { + components['hour'] = currentIndex++; + } else if (str === 'mm') { + components['minute'] = currentIndex++; + } else if (str === 'ss') { + components['second'] = currentIndex++; + } + return ""; + }); + return components; +}; + //初始化面板数据 -Dates.initDate = function(){ +Dates.initDate = function(format){ var S = Dates.query, log = {}, De = new Date(); var ymd = Dates.elem[as.elemv].match(/\d+/g) || []; + var elemIndexMap = Dates.getEachElementIndex(format); + Dates.elemIndexMap = elemIndexMap; if(ymd.length < 3){ ymd = Dates.options.start.match(/\d+/g) || []; if(ymd.length < 3){ @@ -471,7 +495,7 @@ Dates.initDate = function(){ } } Dates.inymd = ymd; - Dates.viewDate(ymd[0], ymd[1]-1, ymd[2]); + Dates.viewDate(ymd[elemIndexMap.year], ymd[elemIndexMap.month] - 1, ymd[elemIndexMap.day]); }; //是否显示零件 @@ -609,7 +633,7 @@ Dates.view = function(elem, options){ options.zIndex ? Dates.box.style.zIndex = options.zIndex : Dates.removeCssAttr(Dates.box, 'z-index'); Dates.stopMosup('click', Dates.box); - Dates.initDate(); + Dates.initDate(options.format); Dates.iswrite(); Dates.check(); }; @@ -631,11 +655,24 @@ Dates.close = function(){ //转换日期格式 Dates.parse = function(ymd, hms, format){ - ymd = ymd.concat(hms); + ymd = ymd.concat(hms); // [year, month, day, hour, minute, second] format = format || (Dates.options ? Dates.options.format : config.format); return format.replace(/YYYY|MM|DD|hh|mm|ss/g, function(str, index){ - ymd.index = ++ymd.index|0; - return Dates.digit(ymd[ymd.index]); + var pos = -1; + if (str === 'YYYY') { + pos = 0; + } else if (str === 'MM') { + pos = 1; + } else if (str === 'DD') { + pos = 2; + } else if (str === 'hh') { + pos = 3; + } else if (str === 'mm') { + pos = 4; + } else if (str === 'ss') { + pos = 5; + } + return Dates.digit(ymd[pos]); }); };