直接上代码:
<div class="layui-form-item layui-form-text"> <label class="layui-form-label">月份</label> <div class="layui-input-block"> <input type="text" name="mouth" class="layui-input" id="mouth"> </div> </div>
<script> layui.use(['table', 'laydate'], function () { var $ = layui.$ , form = layui.form , laydate = layui.laydate , table = layui.table; //时间范围选择 laydate.render({ elem: '#created_at' // ,range: true , range: '至' , max: 0 //7天后 }); laydate.render({ elem: '#interview_date' }); var end = laydate.render({ elem: '#mouth', //选择器结束时间 format: 'yyyy-MM', type: 'month', showBottom: false, //关闭底部框 去掉取消、确定、清空按钮 // 选择年份或者月份都会关闭 change: function (value, date, endDate) { //监听日期被切换 lay('#mouth').val(value); if ($(".layui-laydate").length) { $(".layui-laydate").remove(); } }, //选择月份即选中关闭 年份扔可以左右点击选择 change: function (value, date, endDate) { //监听日期被切换 lay('#mouth').val(value); $('.laydate-month-list').on('click','li',function () {//利用的事件委托 $('.layui-laydate').remove() }) }, done: function (value, date) { start.config.max = { year:value ? date.year : 3099, month: date.month - 1, //关键 date: date.date, hours: 0, minutes: 0, seconds: 0 } } }); }); </script>