现在的情况是alert已经出来了,可是文件还是上传上去了?

功能是要上传一个文件,判断这个文件名称是否已存在,存在的话提示用户修改文件名称。

Java代码  

  1. 'onSelect': function(e, queueId, fileObj) {  

  2. if(checkFileNames(fileObj.name)){  

  3. alert("已存在名为:" + fileObj.name + "的文件,请修改文件名称!");  

  4. return false;  

  5. }  

  6. },  

onSelect方法如上面所示,checkFileNames用于判断文件名是否已存在,存在返回true,不存在返回false。现在的情况是alert已经出来了,可是文件还是上传上去了。怎么破?
求大神~!~


开心每一天1111
浏览 83回答 2
2回答

胡说叔叔

做过类似的东西,是在onUploadStart中判断的,弄了好久才搞定'onUploadStart': function (file) {    var myself = this;    if(已存在){      myself.cancelUpload(file.id);      $('#' + file.id).remove();    }}是根据uploadify源码中改的// Triggered right before a file is uploaded        onUploadStart: function (file) {            // Load the swfupload settings            var settings = this.settings;            var timer = new Date();            this.timer = timer.getTime();            this.bytesLoaded = 0;            if (this.queueData.uploadQueue.length == 0) {                this.queueData.uploadSize = file.size;            }            if (settings.checkExisting) {                $.ajax({                    type: 'POST',                    async: false,                    url: settings.checkExisting,                    data: { filename: file.name },                    success: function (data) {                        if (data == 1) {                            var overwrite = confirm('A file with the name "' + file.name + '" already exists on the server.\nWould you like to replace the existing file?');                            if (!overwrite) {                                this.cancelUpload(file.id);                                $('#' + file.id).remove();                                if (this.queueData.uploadQueue.length > 0 && this.queueData.queueLength > 0) {                                    if (this.queueData.uploadQueue[0] == '*') {                                        this.startUpload();                                    } else {                                        this.startUpload(this.queueData.uploadQueue.shift());                                    }                                }                            }                        }                    }                });            }

德玛西亚99

上传动作我记得好像不是在onSelect里面触发的,因此即使你在onSelect里面return false;不会Break掉上传的动作。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java