初始化之后,假如开始时间最大时间限制在2019-10-24 11 改变月份或日期后,最大时间限制正常
如果改变年份的话,最大时间小时选择只能选到11点,不能选择12-23,截图如下:
改变月份或日期 与改变年份之后,html元素属性一致,截图:
laydate在angularjs中的封装:
.directive('myLayDate', function ($timeout) {
return {
require: '?ngModel',
restrict: 'AE',
scope: {
ngModel: '=',
choose: '&',
min: '@',
max: '@',
istime: '@',
format: '@',
isclear: '@',
istoday: '@',
issure: '@',
festival: '@',
start: '@',
fixed: '@'
},
link: function (scope, element, attr, ngModel) {
$timeout(function(){
ngModel.$render = function () {
element.val(ngModel.$viewValue || '');
};
element.on('blur keyup change', function () {
scope.$apply(read);
});
function read() {
var val = element.val();
ngModel.$setViewValue(val);
}
if (attr.skin) {
laydate.skin(attr.skin);
} else {
laydate.skin('yahui');
}
scope.option = {
elem: '#' + attr.id,
format: scope.format != undefined && attr.format != '' ? attr.format : 'YYYY-MM-DD',
istime: scope.istime,//是否开启时间选择
timerange: scope.timerange || 'hms',
isclear: scope.isclear, //是否显示清空
istoday: scope.istoday, //是否显示今天
issure: scope.issure || true, //是否显示确认
festival: scope.festival, //是否显示节日
min: scope.min || '1900-01-01 00:00:00', //最小日期
max: scope.max || '2099-12-31 23:59:59', //最大日期
start: scope.start || '2014-6-15 23:00:00', //开始日期
fixed: scope.fixed, //是否固定在可视区域
zIndex: 99999999, //css z-index
choose: function (data) {
scope.$apply(read);
scope.$apply(scope.choose);
}
};
function init() {
laydate(scope.option);
}
init();
if(scope.start){
element.val(scope.start);
}
scope.$watch('min', function (newValue, oldValue) {
if (newValue == oldValue)
return;
scope.option.min = newValue;
});
scope.$watch('max', function (newValue, oldValue) {
if (newValue == oldValue)
return;
scope.option.max = newValue;
});
scope.$watch('format', function (newValue, oldValue) {
if (newValue == oldValue)
return;
scope.option.format = newValue;
read();
});
read();
},0);
}
}
});
html代码:
//开始时间
<input type="text"
my-lay-date=""
class="laydate-icon"
autocomplete="off"
id="startDate"
ng-model="startDate.value"
start={{startDate.value}}
istime="{{istime}}"
max="{{startDate.max}}"
min="{{startDate.min}}"
format="{{datetimeformat}}"
timerange="{{timerange}}"
choose="startselect()"/>
//结束时间
<input type="text" my-lay-date=""
class="laydate-icon"
autocomplete="off"
id="endDate"
ng-model="endDate.value"
start="{{endDate.value}}"
istime="{{istime}}"
format="{{datetimeformat}}"
min="{{endDate.min}}"
max="{{endDate.max}}"
timerange="{{timerange}}"/>
js代码:
$scope.startDate = {
'value': moment().format('YYYY-MM-DD HH'),
'max': moment().format('YYYY-MM-DD HH'),
'min': '1951-01-01 00'
}; //开始时间设置
$scope.endDate = {
'value': moment().format('YYYY-MM-DD HH'),
'min': $scope.startDate.value,
'max': moment().add(1, 'hours').format('YYYY-MM-DD HH')
}; //结束时间设置
请问这是什么原因?