How to set the default time in layui?
To set a default time in Layui, you can use the layui.laydate.render() method and set the default time by configuring the value attribute. Here are the specific steps to do so:
- Include the style and script files of Layui in HTML.
<link rel="stylesheet" href="path/to/layui/css/layui.css">
<script src="path/to/layui/layui.js"></script>
- Call the layui.laydate.render() method in JavaScript.
layui.use('laydate', function(){
var laydate = layui.laydate;
// 设置默认时间
laydate.render({
elem: '#demo', // 绑定元素的选择器
value: '2021-01-01', // 设置默认时间
// 其他配置项...
});
});
- Add a selector for binding elements in HTML.
<input type="text" id="demo">
The ‘elem’ parameter in the above code specifies the bound element selector, while the ‘value’ parameter sets the default time. You can modify it according to your own needs.