【发布时间】:2015-10-19 22:41:45
【问题描述】:
// ===========for checking the size of an image
$(document).on('change', '#images', function() {
files = this.files;
size = files[0].size;
//max size 50kb => 50*1000
if (size < 1000141) {
return true;
//break;
// end;
}
alert('File size greater than 1MB cannot be uploaded');
return false;
});
//===========used for showing the preview of image
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#blah').attr('src', e.target.result);
$('#blah').show();
}
reader.readAsDataURL(input.files[0]);
}
}
$("#images").change(function() {
readURL(this);
});
第一个脚本显示警报,但第二个脚本在大小大于 1MB 时提供预览。
【问题讨论】:
-
所以你希望第二个函数只有在文件大小在限制范围内时才能工作,对吧?
标签: javascript jquery ajax codeigniter