Layui时间选择框介绍
Layui中 时间格式的输入框:
html代码:
<div class="layui-inline" style="max-width:90%"> <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代码:
layui.use(['layer', 'form', 'table', 'laydate'], function () { var layer = layui.layer, $ = layui.jquery, form = layui.form, laydate = layui.laydate, table = layui.table; var beginDate = laydate.render({//渲染开始时间选择 elem: '#beginDate', //通过id绑定html中插入的start type: 'datetime', 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: '#endDate',//通过id绑定html中插入的end type: 'datetime', 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 } } }); });
elem: '#endDate' 绑定元素;
type: 'datetime' 选择类型:
max: "2099-12-31 23:59:59" 设置默认最大值
min: "1970-1-1 00:00:00" 设置默认最小值
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 }; }
这个是为了选择开始时间后,结束时间必须大于等于开始时间;
本文转自:https://blog.csdn.net/Third_Week/article/details/96831135
以上就是Layui时间选择框介绍的详细内容,更多请关注www.sxiaw.com其它相关文章!