Home >Web Front-end >Layui Tutorial >Introduction to Layui time selection box

Introduction to Layui time selection box

尚
forward
2020-02-06 16:55:549422browse

Introduction to Layui time selection box

Time format input box in Layui:

html code:

<div class="layui-inline" style="width: fit-content;">
     <label class="layui-form-label" style="width: fit-content;">选择日期:</label>
     <div class="layui-input-inline" style="width: 150px">
         <input type="text" name="beginDate" id="beginDate" lay-verify="datetime" class="layui-input">
     </div>
     --
     <div class="layui-form-mid">-</div>
         <div class="layui-input-inline" style="width: 150px">
         <input type="text" name="endDate" id="endDate" lay-verify="datetime" class="layui-input">
     </div>
</div>

js code:

layui.use([&#39;layer&#39;, &#39;form&#39;, &#39;table&#39;, &#39;laydate&#39;], function () {
    var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form,
                laydate = layui.laydate,
                table = layui.table;
 
    var beginDate = laydate.render({//渲染开始时间选择
        elem: &#39;#beginDate&#39;, //通过id绑定html中插入的start
        type: &#39;datetime&#39;,
        max: "2099-12-31 23:59:59",//设置一个默认最大值
        done: function (value, dates) {
                endDate.config.min = {
                    year: dates.year,
                    month: dates.month - 1, //关键
                    date: dates.date,
                    hours: dates.hours,
                    minutes: dates.minutes,
                    seconds: dates.seconds
                };
        }
    });
    var endDate = laydate.render({//渲染结束时间选择
        elem: &#39;#endDate&#39;,//通过id绑定html中插入的end
        type: &#39;datetime&#39;,
        min: "1970-1-1 00:00:00",//设置min默认最小值
        done: function (value, dates) {
                beginDate.config.max = {
                    year: dates.year,
                    month: dates.month - 1,//关键
                    date: dates.date,
                    hours: dates.hours,
                    minutes: dates.minutes,
                    seconds: dates.seconds
                }
        }
    });
});

Introduction to Layui time selection box

elem: '#endDate' binding element;

type: 'datetime' selection type:

Introduction to Layui time selection box

##max: "2099-12 -31 23:59:59" Set the default maximum value

min: "1970-1-1 00:00:00" Set the default minimum value

done: function (value, dates) {
                endDate.config.min = {
                    year: dates.year,
                    month: dates.month - 1, //关键
                    date: dates.date,
                    hours: dates.hours,
                    minutes: dates.minutes,
                    seconds: dates.seconds
                };
            }

This is for selecting the start time , the end time must be greater than or equal to the start time;

This article is reproduced from: https://blog.csdn.net/Third_Week/article/details/96831135

For more layui knowledge, please pay attention

layui usage tutorial column.

The above is the detailed content of Introduction to Layui time selection box. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete