使用jquery.uploadify.v2.1.0开发时,将图片大小限制为不超过4M,想在用户图片超过这个大小的时候弹出对话框报错。但是onSelect事件不触发,onSelectOnce事件触发但是无法拿到图片大小,onSelectError/onError/onUploadError均不触发。想问下有谁处理过类似的情况么?
return this.each(function () {
var $this = $(this);
$this.uploadify({
uploader: uploaderUrl,
cancelImg: '',
buttonImg: "http://img.soufun.com/secondhouse/image/erp/icon_add2img.jpg",
expressInstall: 'http://img.soufun.com/secondhouse/image/erp/expressInstall.swf',
width: 108,
height: 30,
fileDesc: '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
fileExt: '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
sizeLimit: 4194304,
auto: false,
multi: true,
onSelect: function (e, queueId, fileObj) {
alert(1) //图片超出大小时不触发
$this.uploadifySettings('script', postUrl);
},
onSelectOnce: function (e, data) {
//一直触发但拿不到用户上传的图片大小的值
totalImgCount += data.fileCount;
if (totalImgCount > options.maxCount) {
alert("最多上传" + options.maxCount + "张");
return;
}
$this.parent().append(processDom);
$this.uploadifyUpload();
},
uploadifyOverSize : function(){
//图片大小超出时不触发
alert(123);
},
onSelectError: function () {
//图片大小超出时不触发
alert(456);
},
onUploadError : function(){
//图片大小超出时不触发
alert(789)
},
onError : function(){
////图片大小超出时不触发
alert(1011)
},
onProgress: function (event, queueId, fileObj, data) { //data对象有四个属性percentage、 bytesLoaded、allBytesLoaded、speed
var process_width = data.percentage / 100 * 200 + "px";
$this.parent().find("img.imgprocess").css({
width : process_width
});
if (data.percentage == 100) {
$this.parent().find("div.processContainer").remove();
}
},
onComplete: function (event, queueId, fileObj, response, data) {
if (options.domType == "normal") {
$this.parent().append(dom_normal);
}
options.onComplete(fileObj, response);
},
queueID: 'divQueue',
scriptAccess: 'always'
})
试一下onUploadError或onDisable(没有配环境, 题主自测一下)
传送门: http://www.uploadify.com/docu...