Flatpickr 用所选日期填充 div 文本
Flatpickr populate div text with chosen date
当您输入 input
时,我的 .auto-input
函数会填充容器 div .text
,但它不会获取 [=16= 中的值] 字段并在选择日期时填充 .flatpickr
div 文本。
如何让 .flatpickr
中的文本根据来自 #flapickr
的输入进行填充?
$('.auto-input').keyup(function() {
var $this = $(this);
$('.' + $this.attr('id') + '').html($this.val());
});
var example = flatpickr("#flatpickr", {
locale: "en",
altInput: true,
dateFormat: "d-m-Y",
minDate: "1950-01-01",
allowInput: false
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="input-wrapper">
<input class="auto-input" id="text" type="text" /><br/>
<input class="auto-input" id="flatpickr" type="text" placeholder="deal expires on...">
</div>
<div class="input-fill-holder">
<div class="text"></div>
<div class="flatpickr">Fill Date Here</div>
</div>
<link href="https://npmcdn.com/flatpickr/dist/flatpickr.css" rel="stylesheet" type="text/css">
<link href="https://npmcdn.com/flatpickr/dist/themes/airbnb.css" rel="stylesheet" type="text/css">
<script src="https://npmcdn.com/flatpickr/dist/flatpickr.min.js"></script>
<script src="https://npmcdn.com/flatpickr/dist/l10n/fr.js"></script>
您必须添加 onChange
或 onClose
事件挂钩,然后相应地更新 .flatpickr
div。在这里阅读更多:https://flatpickr.js.org/events/#hooks
这里是fiddle:https://jsfiddle.net/yhn4peey/4/
示例如下:
$('.auto-input').keyup(function() {
var $this = $(this);
$('.' + $this.attr('id') + '').html($this.val());
});
var example = flatpickr("#flatpickr", {
locale: "en",
altInput: true,
dateFormat: "d-m-Y",
minDate: "1950-01-01",
allowInput: false,
onChange: function(selectedDates, dateStr, instance) {
$(".flatpickr").html(dateStr);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="input-wrapper">
<input class="auto-input" id="text" type="text" /><br/>
<input class="auto-input" id="flatpickr" type="text" placeholder="deal expires on...">
</div>
<div class="input-fill-holder">
<div class="text"></div>
<div class="flatpickr">Fill Date Here</div>
</div>
<link href="https://npmcdn.com/flatpickr/dist/flatpickr.css" rel="stylesheet" type="text/css">
<link href="https://npmcdn.com/flatpickr/dist/themes/airbnb.css" rel="stylesheet" type="text/css">
<script src="https://npmcdn.com/flatpickr/dist/flatpickr.min.js"></script>
<script src="https://npmcdn.com/flatpickr/dist/l10n/fr.js"></script>
当您输入 input
时,我的 .auto-input
函数会填充容器 div .text
,但它不会获取 [=16= 中的值] 字段并在选择日期时填充 .flatpickr
div 文本。
如何让 .flatpickr
中的文本根据来自 #flapickr
的输入进行填充?
$('.auto-input').keyup(function() {
var $this = $(this);
$('.' + $this.attr('id') + '').html($this.val());
});
var example = flatpickr("#flatpickr", {
locale: "en",
altInput: true,
dateFormat: "d-m-Y",
minDate: "1950-01-01",
allowInput: false
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="input-wrapper">
<input class="auto-input" id="text" type="text" /><br/>
<input class="auto-input" id="flatpickr" type="text" placeholder="deal expires on...">
</div>
<div class="input-fill-holder">
<div class="text"></div>
<div class="flatpickr">Fill Date Here</div>
</div>
<link href="https://npmcdn.com/flatpickr/dist/flatpickr.css" rel="stylesheet" type="text/css">
<link href="https://npmcdn.com/flatpickr/dist/themes/airbnb.css" rel="stylesheet" type="text/css">
<script src="https://npmcdn.com/flatpickr/dist/flatpickr.min.js"></script>
<script src="https://npmcdn.com/flatpickr/dist/l10n/fr.js"></script>
您必须添加 onChange
或 onClose
事件挂钩,然后相应地更新 .flatpickr
div。在这里阅读更多:https://flatpickr.js.org/events/#hooks
这里是fiddle:https://jsfiddle.net/yhn4peey/4/
示例如下:
$('.auto-input').keyup(function() {
var $this = $(this);
$('.' + $this.attr('id') + '').html($this.val());
});
var example = flatpickr("#flatpickr", {
locale: "en",
altInput: true,
dateFormat: "d-m-Y",
minDate: "1950-01-01",
allowInput: false,
onChange: function(selectedDates, dateStr, instance) {
$(".flatpickr").html(dateStr);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="input-wrapper">
<input class="auto-input" id="text" type="text" /><br/>
<input class="auto-input" id="flatpickr" type="text" placeholder="deal expires on...">
</div>
<div class="input-fill-holder">
<div class="text"></div>
<div class="flatpickr">Fill Date Here</div>
</div>
<link href="https://npmcdn.com/flatpickr/dist/flatpickr.css" rel="stylesheet" type="text/css">
<link href="https://npmcdn.com/flatpickr/dist/themes/airbnb.css" rel="stylesheet" type="text/css">
<script src="https://npmcdn.com/flatpickr/dist/flatpickr.min.js"></script>
<script src="https://npmcdn.com/flatpickr/dist/l10n/fr.js"></script>