FIx: 默认container为''(body会计算位置)

pull/77/head
Maorey 2018-09-11 14:22:49 +08:00
parent 3810167f2c
commit 35095f2dd0
3 changed files with 99 additions and 14 deletions

2
dist/laydate.js vendored

File diff suppressed because one or more lines are too long

View File

@ -391,7 +391,7 @@
, zIndex: null //控件层叠顺序 , zIndex: null //控件层叠顺序
, done: null //控件选择完毕后的回调,点击清空/现在/确定也均会触发 , done: null //控件选择完毕后的回调,点击清空/现在/确定也均会触发
, change: null //日期时间改变后的回调 , change: null //日期时间改变后的回调
, container: 'body' // 日期组件容器 , container: '' // 日期组件容器
}; };
//多语言 //多语言
@ -732,7 +732,7 @@
default: default:
container = 0; container = 0;
} }
container ? container.append(elem) : isStatic ? options.elem.append(elem) : ( container ? container.append(elem) : isStatic ? options.elem.append(elem) : (
document.body.appendChild(elem) document.body.appendChild(elem)
, that.position() //定位 , that.position() //定位

View File

@ -3,16 +3,42 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>限制时间范围</title> <title>测试</title>
<script src="../src/laydate.js"></script> <script src="../src/laydate.js"></script>
<style>
.line {
display: inline-block;
width: 200px;
}
</style>
</head> </head>
<body> <body>
<input id="start" placeholder="请选择日期" /> <p>日期选择(固定页面位置)</p>
<div id="start_date"></div> <div class="line">
<input class="date" id="start" placeholder="请选择开始日期" />
</div>
<div class="line">
<input class="date" id="end" placeholder="请选择结束日期" />
</div>
<input id="end" placeholder="请选择日期" /> <p>时间选择</p>
<div id="end_date"></div> <div class="line">
<input class="date" id="start1" placeholder="请选择开始时间" />
</div>
<div class="line">
<input class="date" id="end1" placeholder="请选择结束时间" />
</div>
<p>日期选择(指定控件容器)</p>
<div class="line">
<input class="date" id="start2" placeholder="请选择开始日期" />
<div id="start2_date"></div>
</div>
<div class="line">
<input class="date" id="end2" placeholder="请选择结束日期" />
<div id="end2_date"></div>
</div>
<script> <script>
function setAtts(obj, target) { function setAtts(obj, target) {
@ -21,24 +47,83 @@
} }
} }
// 日期选择(固定页面位置)
var start = laydate.render({ var start = laydate.render({
elem: '#start', elem: '#start',
container: '#start_date', change: console.log,
type: 'time',
done: function (value, date) { done: function (value, date) {
setAtts(end.config.min, { setAtts(end.config.min, {
year: date.year || 1900,
month: date.month && --date.month || 1,// 因为js Date月是从0开始的...
date: date.date || 1
});
}
});
var end = laydate.render({
elem: '#end',
change: console.log,
done: function (value, date) {
setAtts(start.config.max, {
year: date.year || 2099,
month: date.month && --date.month || 12,// 因为js Date月是从0开始的...
date: date.date || 30
});
}
});
// 时间选择
var start1 = laydate.render({
elem: '#start1',
type: 'time',
change: console.log,
done: function (value, date) {
setAtts(end1.config.min, {
hours: date.hours || 0, hours: date.hours || 0,
minutes: date.minutes || 0, minutes: date.minutes || 0,
seconds: date.seconds || 0 seconds: date.seconds || 0
}); });
} }
}); });
var end = laydate.render({ var end1 = laydate.render({
elem: '#end', elem: '#end1',
container: '#end_date',
type: 'time', type: 'time',
change: console.log,
done: function (value, date) { done: function (value, date) {
setAtts(start.config.max, date || { setAtts(start1.config.max, {
hours: date.hours || 23,
minutes: date.minutes || 59,
seconds: date.seconds || 59
});
}
});
// 日期选择(指定控件容器)
var start2 = laydate.render({
elem: '#start2',
container: '#start2_date',
type: 'datetime',
change: console.log,
done: function (value, date) {
setAtts(end2.config.min, {
year: date.year || 1900,
month: date.month && --date.month || 1,// 因为js Date月是从0开始的...
date: date.date || 1,
hours: date.hours || 0,
minutes: date.minutes || 0,
seconds: date.seconds || 0
});
}
});
var end2 = laydate.render({
elem: '#end2',
container: '#end2_date',
type: 'datetime',
change: console.log,
done: function (value, date) {
setAtts(start2.config.max, {
year: date.year || 2099,
month: date.month && --date.month || 12,// 因为js Date月是从0开始的...
date: date.date || 30,
hours: date.hours || 23, hours: date.hours || 23,
minutes: date.minutes || 59, minutes: date.minutes || 59,
seconds: date.seconds || 59 seconds: date.seconds || 59