在弹出层使用layui.laydate,一般会出现点击无效,不弹出,或者一闪而过,切换页面才会显示的问题,正确实现代码是:
add: function () {
$("#isNew").val(1);
$('#myForm')[0].reset();
form.render();
layer.open({
type: 1
, title: '添加'
, content: $('#inputInfo')
, maxmin: true
, area: ['60%','80%'],
success: function(layero, index){
layui.use('laydate', function() {
var laydate = layui.laydate;
laydate.render({elem: '#startDate', type: 'date', trigger: 'click', range: false,});
laydate.render({elem: '#startTime', type: 'time', trigger: 'click', range: false,});
laydate.render({elem: '#endTime', type: 'time', trigger: 'click', range: false,});
});
}
});
}
在open之前,先reset,然后 $(’#myForm’)是对应的弹出层
<form class="layui-form layui-form-wd120" lay-filter="myForm" id="myForm">
add是添加方法
<button class="layui-btn btn-action" data-type="add">
<i class="layui-icon layui-icon-addition layuiadmin-button-btn"></i> 添加
</button>
如果是编辑,写成这样
function edit(aData) {
form.val('myForm', aData);
layer.open({
type: 1
, title: '编辑'
, content: $('#inputInfo')
, maxmin: true
,area: ['60%','80%'],
success: function(layero, index){
layui.use('laydate', function() {
var laydate = layui.laydate;
laydate.render({elem: '#startDate', type: 'date', trigger: 'click', range: false,});
laydate.render({elem: '#startTime', type: 'time', trigger: 'click', range: false,});
laydate.render({elem: '#endTime', type: 'time', trigger: 'click', range: false,});
});
}
});
form.render();
}