laydate 日期格式为yyyy 或yyyy-MM时,出现错误Uncaught TypeError: Cannot read property 'length' of undefined
这个改起比较麻烦,没有深究,简单兼容了yyyy 和yyyy-MM,其他格式可能还是会有错误。替换Dates.check方法。
//检测日期是否合法 Dates.check = function(){ var reg = Dates.options.format.replace(/YYYY|MM|DD|hh|mm|ss/g,'\\d+\\').replace(/\\$/g, ''); var exp = new RegExp(reg), value = Dates.elem[as.elemv]; var arr = value.match(/\d+/g) || [], isvoid = Dates.checkVoid(arr[0], arr[1], arr[2]); if(value.replace(/\s/g, '') !== ''){ if(!exp.test(value)){ Dates.elem[as.elemv] = ''; Dates.msg('日期不符合格式,请重新选择。'); return 1; } else if(isvoid[0]){ Dates.elem[as.elemv] = ''; Dates.msg('日期不在有效期内,请重新选择。'); return 1; } else { isvoid.value = Dates.elem[as.elemv].match(exp).join(); arr = isvoid.value.match(/\d+/g); if (arr.length > 1) { if (arr[1] < 1) { arr[1] = 1; isvoid.auto = 1; } else if (arr[1] > 12) { arr[1] = 12; isvoid.auto = 1; } else if (arr[1].length < 2) { isvoid.auto = 1; } } if (arr.length > 2) { if (arr[2] < 1) { arr[2] = 1; isvoid.auto = 1; } else if (arr[2] > Dates.months[(arr[1] | 0) - 1]) { arr[2] = 31; isvoid.auto = 1; } else if (arr[2].length < 2) { isvoid.auto = 1; } } if(arr.length > 3){ if(Dates.timeVoid(arr[3], 0)){ isvoid.auto = 1; }; if(Dates.timeVoid(arr[4], 1)){ isvoid.auto = 1; }; if(Dates.timeVoid(arr[5], 2)){ isvoid.auto = 1; }; } if(isvoid.auto){ Dates.creation([arr[0], arr[1]|0, arr[2]|0], 1); } else if(isvoid.value !== Dates.elem[as.elemv]){ Dates.elem[as.elemv] = isvoid.value; } } } };
两个黄鹂鸣翠柳,一行代码上青天