遇到个很奇怪的问题,
在按钮触发弹窗中使用upload后,用弹窗自带的按钮无法触发upload的bindAction事件,
如果页面不用过按钮触发弹窗,既页面加载后显示弹窗,则需要写两个upload.render,才额可以绑定成功弹窗的按钮
以下是代码:
[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Layui</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="layui-v2.7.6/layui/css/layui.css" media="all">
</head>
<body>
<div style="display:none" id="test">
<div style="padding-top: 20px; margin-right:50px;">
<table class="form">
<tr style="line-height:50px">
<td class="formTitle">请选择文件:</td>
<td class="formValue">
<input type="file" name="file" id="test20">
</td>
</tr>
</table>
</div>
</div>
<button class="layui-btn">事件1</button>
<script src="layui-v2.7.6/layui/layui.js" charset="utf-8"></script>
<script>
var $ = layui.jquery
, upload = layui.upload
, element = layui.element
, layer = layui.layer
, util = layui.util;
layer.open({
type: 1,
btn: ['上传'],
content: $('#test'),
yes: function () {
upload.render({
elem: '#test20',
accept: 'file'
, url: 'add' //上传接口
, auto: false
, bindAction: '.layui-layer-btn0'
, done: function (res) {
layer.msg('上传成功');
console.log(res)
}
});
}
})
upload.render({
elem: '#test20',
accept: 'file'
, url: 'add' //上传接口
, auto: false
, bindAction: '.layui-layer-btn0'
, done: function (res) {
layer.msg('上传成功');
console.log(res)
}
});
function down() {
layer.open({
type: 1,
btn: ['上传1'],
content: $('#test'),
yes: function () {
upload.render({
elem: '#test20',
accept: 'file'
, url: 'add' //上传接口
, auto: false
, bindAction: '.layui-layer-btn0'
, done: function (res) {
layer.msg('上传成功');
console.log(res)
}
});
}
})
}
</script>
</body>
</html>
|