layui之upload上传excel表格基础版

layui之upload上传excel表格

    layui.use(['form', 'layer','element','upload'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var upload = layui.upload;

    //选完文件后不自动上传
    upload.render({
        elem: '#student-upload-change',
        url: '你的后台api接口',
        accept: 'file', //普通文件
        exts: 'xls|xlsx', //只允许上传excel文件
        auto: false, //是否自动上传
        field: 'student-upload-change', //重点:后台验证的表单名称
        //multiple: true,
        bindAction: '#student-upload-change-action',
        done: function(res){
            if (200 === res.code) {
                layer.msg(res.msg, {icon: 1});
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        },
        error: function () {
            //请求异常回调
        }
    });

 

上一篇:layer系列之table表及导出+打印功能总结


下一篇:layui弹出层打开后马上关闭问题解决