layui上传

        先引入js和css文件。/** layui-v2.2.5 MIT License By https://www.layui.com */

        这个版本增加了新功能,下面用的到

        本次应用场景是列表中每一条数据都对应一个上传按钮。

table中大概情景

<tr>

<td><a class="upload" value="val" href="javascript:;" title="上传"> <i class="layui-icon">&#xe62f;</i> </a></td>

<td><a class="upload" value="val" href="javascript:;" title="上传"> <i class="layui-icon">&#xe62f;</i> </a></td>

</tr>

js代码如下:

layui.use('upload', function() {
        var upload = layui.upload;
        upload.render({
            elem : '.upload',
            accept : 'file',
            url : '${ctx}/uploadData',
            before : function(obj) {
                layer.load(); //上传loading
                //获取当前对象(必须是2.2版本已上的js,才有item这个东西)
                var projectId = $(this.item[0]).attr("value");
                this.data = {
                    'projectId' : projectId
                };
            },
            done : function(res, index, upload) {
                if (res.success) {
                    layer.closeAll('loading'); //关闭loading
                    layer.msg(res.msg);
                    setTimeout(function() {
                        $("#searchForm").submit();
                    }, 500);
                } else {
                    layer.closeAll('loading'); //关闭loading
                    layer.msg(res.msg);
                    setTimeout(function() {
                        $("#searchForm").submit();
                    }, 500);
                }

            }
        });

    });

后台接收和普通的一样,用file字段接收就行

实在不会排版。。。委屈

猜你喜欢

转载自blog.csdn.net/lixiaoyi01/article/details/79766669