jQuery文件上传插件:如何在添加时验证文件? [英] Jquery file upload plugin: how to validate files on add?

查看:97
本文介绍了jQuery文件上传插件:如何在添加时验证文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$('#fileupload')
    .fileupload({
        acceptFileTypes: /(\.|\/)(jpg)$/i
    })
    .on('fileuploadadd', function (e, data) {
        console.log(data.files.valid); //undefined
        setTimeout(function () {
            console.log(data.files.valid); //true or false
        }, 500);
    })
;

jsFiddle

如何在没有超时的情况下获取属性data.files.valid的布尔值?

jsFiddle

How to get boolean value of property data.files.valid without timeout ?

推荐答案

这是您要执行的操作:

$('#fileupload')
    .fileupload({
        acceptFileTypes: /(\.|\/)(jpg)$/i
    })
    .bind('fileuploadadded', function (e, data) {
        console.log(data.files.valid);
    });

核心jquery.fileupload.js文件正在添加文件并触发"fileuploadadd"事件,但这是在之前进行验证的文件.

The core jquery.fileupload.js file is adding your files and triggering the "fileuploadadd" event, but that's before the files are validated.

文件添加后,文件jquery.fileupload-ui.js正在进行验证,并在完成后触发另一个"fileuploadadded"事件.

The file jquery.fileupload-ui.js is doing the validation after the files are added, and triggering another "fileuploadadded" event once that's done.

更改事件,一切就绪.

此答案自发布之日起至2013年3月有效.此后看来,此上传插件已更改.这意味着有一个新问题,您应该发布一个新问题(或搜索以查看某人是否已有问题),而不是否决这个问题!

这篇关于jQuery文件上传插件:如何在添加时验证文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆