javascript 日期选择器flatpickr.js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 日期选择器flatpickr.js相关的知识,希望对你有一定的参考价值。

<?php

loadFile("css", "flatpickr", "flatpickr.min");
loadFile("js", "flatpickr", "flatpickr.min");

// load datepicker language file based on current lang
$locale = "en";
$locale_file = $config->paths->templates . "lib/flatpickr/l10n/" . $locale . ".js";
if(file_exists($locale_file)) {
    loadFile("js", "flatpickr/l10n", "$locale");
}

?>

<form action="./" method="POST">
  <input class="datePicker" type="text" name="check_in" placeholder="Check In" required />
  <input class="datePicker2" type="text" name="check_out" placeholder="Check Out" required />
</form>
$(document).ready(function() {
    
    // set localization (laod localization file from from l10ns folder)
    flatpickr.localize(flatpickr.l10ns.en);

    $(".datePicker").flatpickr({
        dateFormat: "d M Y",
        altInput: true,
        altFormat: "d M Y",
        minDate: "today",
    });
    
    // For mobile, need to init flatpickr for each input
    $(".datePicker2").flatpickr({
        dateFormat: "d M Y",
        altInput: true,
        altFormat: "d M Y",
        minDate: "today",
    });

    $(".datePicker").on('change', function(e) {

        /** 
         * When date1 is set, make it as minimum date for date2
         * 
         */
        
        var date1 = $("input[name=check_in]").val();
        var newMinDate = new Date(date1);
        
        $(".datePicker2").flatpickr({
            dateFormat: "d M Y",
            altInput: true,
            altFormat: "d M Y",
            minDate: newMinDate,
        });

    });


});

以上是关于javascript 日期选择器flatpickr.js的主要内容,如果未能解决你的问题,请参考以下文章

flatpickr功能强大的日期时间选择器插件

Livewire 和 Flatpickr - 重新渲染后失败

flatpickr 字段不显示表单验证消息?

JavaScript:日期选择器组件的使用

JavaScript:日期选择器组件的使用

无法使用 javascript 弹出日期选择器