gpt4 book ai didi

jquery - 如何获取来自 flatpickr 的日期输入?

转载 作者:行者123 更新时间:2023-12-01 04:34:17 24 4
gpt4 key购买 nike

我正在将我的 jquery ui datepicker 更改为 flatpickr。但我需要知道如何为 flatpickr 执行此 $('#from2').datepicker('getDate') 。我在网上找不到如何使用 flatpickr 进行操作。

感谢您的宝贵时间。

*编辑

function getDays() {
let start = $('#from1').datepicker('getDate'),
end = $('#to1').datepicker('getDate'),
days = (end - start) / 1000 / 60 / 60 / 24;
if(days == 0 || days > 0) {
$('#howManyNights').val(days);
}
return days;
}

*不适用于 flatpickr:

function getDays() {
let start = $('#from1').val();
end = $('#to1').val();
days = (end - start) / 1000 / 60 / 60 / 24;
console.log(days);
if(days == 0 || days > 0) {
$('#howManyNights').val(days);
}
return days;
}

天=南

最佳答案

尝试这样,通过使用 flatpickr 的值创建日期对象(您可以运行的工作片段)

var from1 = flatpickr('#from1', {});
var to1 = flatpickr('#to1', {});

function getDays() {
var start = new Date($('#from1').val());
var end = new Date($('#to1').val());
days = (end - start) / 1000 / 60 / 60 / 24;
if(days == 0 || days > 0) {
$('#howManyNights').val(days);
}
return days;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.3/flatpickr.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.3/flatpickr.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

From:<input name="from1" id="from1" type="text">
To:<input name="to1" id="to1" type="text">
How Many:<input name="howManyNights" id="howManyNights" type="text">
<button onclick="getDays()">Get Days</button>

关于jquery - 如何获取来自 flatpickr 的日期输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59831438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com