layui阻止文件上传

1、找到upload.js,查找:y=function,并将它后面的大括号代码注释,替换成以下的代码:

        return "choose"===t?l.choose&&l.choose(g):((l.before&&l.before(g))===false?'':a.ie?a.ie>9?u():c():void u());

2、借助layui的before方法,使用:return false 阻止提交,如下代码:    

 before : function (obj) {
    //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9)
    obj.preview(function(index, file, result){
        // 非xlsx文件不进行上传并提示
        if(file.name.length > 0){
            var fileName = file.name;
            var fileSuffix = fileName.substr((fileName.lastIndexOf(".")+1),fileName.length);
            if("xlsx" != fileSuffix){
                layer.open({
                    icon:0,
                    title: advice
                    ,content: tips
                });
                return false;
            }
        }
    });
 }
发布了30 篇原创文章 · 获赞 15 · 访问量 2933

猜你喜欢

转载自blog.csdn.net/qq_40891009/article/details/102786634