layui laydate 渲染失效问题,lay-key导致动态生成代码二次渲染失败

在使用layui的laydate动态生成时间选择框时,遇到点击无效或闪现消失的问题。原因是laydate在原始input上添加了lay-key属性,导致新克隆的节点渲染失败。解决方法是移除克隆节点上的lay-key属性,如使用jQuery的removeAttr('lay-key')。
摘要由CSDN通过智能技术生成

在开发中因为需要动态生成时间选择框,所以选择了layui的 laydate控件,但是遇到了生成的时间选择框点击无效的问题,然后再次render 时间选择器一闪就消失了,查了多方资料,找到了如下的解决方法
首先来看下写的demo代码
首先是 html代码

<div class="box">时间选择<input type="text" id="datePick"></div> <button onclick="addOne()">克隆</button>
    
  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
您好,根据您的描述,我理解您想要动态修改 layui-v2.5.5 和 lay-config1.0.4 版本中的 xfile 组件的参数并重新渲染。如果我的理解有误,请及时纠正。 首先,您可以通过修改 xfile 组件的参数来达到动态修改的目的。具体来说,可以通过调用 layui.use 方法来加载 xfile 组件并初始化,然后通过 layui.config 方法来修改 xfile 组件的参数,最后再调用 xfile 组件的渲染方法来重新渲染。 以下是一个示例代码,供您参考: ```html <div class="layui-upload"> <button type="button" class="layui-btn" id="test">上传文件</button> <div class="layui-upload-list"> <table class="layui-table"> <thead> <tr><th>文件名</th><th>大小</th><th>操作</th></tr> </thead> <tbody id="demoList"></tbody> </table> </div> </div> ``` ```javascript layui.use(['upload', 'xfile'], function(){ var upload = layui.upload; var xfile = layui.xfile; // 初始化 xfile 组件 xfile.render({ elem: '#test', url: '/upload/', done: function(res){ // 上传完毕回调 console.log(res); } }); // 修改 xfile 组件的参数 layui.config({ base: '/static/js/layui/lay/modules/xfile/', version: '1.0.4' }).extend({ xfile: 'xfile', }).use(['xfile'], function(){ var xfile = layui.xfile; xfile.config({ size: 1024 * 10, exts: 'doc|docx|xls|xlsx', multiple: true, choose: function(obj){ console.log(obj); } }); }); // 重新渲染 xfile 组件 xfile.render({ elem: '#test' }); }); ``` 在上述示例代码中,我们首先通过 layui.use 方法加载了 upload 和 xfile 组件,并使用 xfile.render 方法初始化了 xfile 组件。然后,我们通过 layui.config 方法来修改 xfile 组件的参数,并使用 xfile.render 方法重新渲染了 xfile 组件。其中,xfile.config 方法用于修改 xfile 组件的参数,size 参数用于限制文件大小,exts 参数用于限制文件类型,multiple 参数用于支持多文件上传,choose 回调函数用于选择文件后的回调。 希望这个示例代码能够对您有所帮助。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值