<fieldset class="layui-elem-field" style="width:500px;margin:50px 0 0 300px;">
<legend>上传回调图片会在这里显示 - 淘素材</legend>
<div class="layui-field-box">
<div style="width:300px;float:left;">
<img src="" style="max-width:320px;float:left;" id="showimg">
</div>
<div style="float:left;margin:0 0 20px 30px;">
<button type="button" class="layui-btn" id="test1">
<i class="layui-icon"></i>上传图片
</button>
</div>
</div>
</fieldset>
1 layui.use(['upload','form'], function(){ 2 var upload = layui.upload,form = layui.form; 3 var uploadInst = upload.render({ 4 elem: '#test1' //绑定元素 5 ,url: 'demo.php' //上传接口 6 ,done: function(res){ 7 $('#showimg').attr('src',res.url); 8 } 9 ,error: function(){ 10 layer.msg('上传失败'); 11 } 12 }); 13 });
具体演示:http://www.jq8868.com/a/83.html