<table width="100%" id="attrTable" class="layui-table">
<thead>
<tr>
<th colspan="2">
<b>
商品相册
</b>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="label" style="width: 120px; text-align: right;">
通用
</td>
<td class="spec" style="text-align: left;">
<div class="photolist">
</div>
<button type="button" class="upload goods_photo_upload" lay-data="{url: '/admin/goods/upfile.html'}"
goods_attr_id="0" title="上传图片">
</button>
</td>
</tr>
<tr>
<td class="label" style="width: 120px; text-align: right;">
红
</td>
<td class="spec" style="text-align: left;">
<div class="photolist">
</div>
<button type="button" class="upload goods_photo_upload" lay-data="{url: '/admin/goods/upfile/goods_attr_id/142228.html'}"
goods_attr_id="142228" title="上传图片">
</button>
</td>
</tr>
<tr>
<td class="label" style="width: 120px; text-align: right;">
白
</td>
<td class="spec" style="text-align: left;">
<div class="photolist">
</div>
<button type="button" class="upload goods_photo_upload" lay-data="{url: '/admin/goods/upfile/goods_attr_id/142229.html'}"
goods_attr_id="142229" title="上传图片">
</button>
</td>
</tr>
</tbody>
</table>
//商品相册上传
var uploadInst= function(element){
upload.render({
elem: element
,method: 'post' //可选项。HTTP类型,默认post
,data: {goods_id:'32948'} //可选项。额外的参数,如:{id: 123, abc: 'xxx'}
,accept:"images"//指定允许上传时校验的文件类型,可选值有:images(图片)、file(所有文件)、video(视频)、audio(音频)
,acceptMime:'image/*'//(只显示图片文件)'image/jpg, image/png'(只显示 jpg 和 png 文件)
,size:1024*2//单位 KB
,multiple:'true'//是否允许多文件上传。设置 true即可开启。不支持ie8/9
,before: function(obj){
//预读本地文件示例,不支持ie8
obj.preview(function(index, file, result){
//$('#demo1').attr('src', result); //图片链接(base64)
});
}
,done: function(res){
var that = this;
var item = this.item;
if (res.code ==200) {
$(item).siblings('.photolist').append(res.data);
layer.msg(res.msg);
} else {
layer.msg(res.msg);
}
console.log(item);
}
,error: function(){
//演示失败状态,并实现重传
layer.msg('上传失败');
}
});
}
uploadInst('.goods_photo_upload');
当html部分是自己生成时,加载完成后 不要忘记重新渲染,要不然不能上传,生成代码后调用uploadInst('.goods_photo_upload');渲染