我遇到了我寫的腳本的問題。從功能中的函數內輸出變量
我想輸出變量error
與true
或false
。
我無法獲得從'fileErrors
'函數輸出的error
變量。
任何人都可以看看下面的代碼,並告訴我,爲什麼它不輸出明顯的問題?
function file() {
var error;
if (window.File && window.FileList && window.FileReader) {
if (!((type == 'jpg') || (type == 'jpeg'))) {
$('#file-info').html('Wrong file type. JPG and JPEG only.').slideDown('slow');
$('.upload-button').attr("disabled", true);
error = true;
} else {
var fileSize = $('.file_field input[type=file]')[0].files[0].size;
var maxFileSize = 8388608;
var maxFileDimension = 1920;
var fileWidth;
var fileHeight;
var url = window.URL || window.webkitURL;
var fileField = $('.file_field input[type=file]')[0].files[0];
var image = new Image();
image.onload = function() {
fileWidth = this.width;
fileHeight = this.height;
fileErrors();
};
image.src = url.createObjectURL(fileField);
function fileErrors() {
if (fileWidth > maxFileDimension || fileHeight > maxFileDimension) {
$('#file-info').html('File dimensions exceed '+maxFileDimension+'px.').slideDown('slow');
$('.upload-button').attr("disabled", true);
error = true;
} else if (fileSize > maxFileSize) {
$('#file-info').html('File exceeding maximum file size.').slideDown('slow');
$('.upload-button').attr("disabled", true);
error = true;
} else {
$('#file-info').slideUp();
$('.upload-button').attr("disabled", false);
error = false;
}
};
}
} else {
if (!((type == 'jpg') || (type == 'jpeg'))) {
$('#file-info').html('Wrong file type. JPG and JPEG only.').slideDown('slow');
$('.upload-button').attr("disabled", true);
error = true;
} else {
$('#file-info').slideUp();
$('.upload-button').attr("disabled", false);
error = false;
}
}
console.log(error);
};
等什麼你從日誌中得到些什麼? – dsharew