当我上传大小大于1Mb的图像时,警报正在起作用,并且图像也已上传。谁能帮帮我吗?
$(document).on('change', '#images', function(){
files = this.files;
size = files[0].size;
if (size < 1000141) {
return true;
// exit();
// end;
}
alert('Please upload less than 1mb file');
return false;
return true;
});
//to show the preview of uploaded 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);
});
最佳答案
return true
之后是return false
。如下更改
$(document).on('change', '#images', function(){
files = this.files;
size = files[0].size;
if (size < 1000141) {
return true;
// exit();
// end;
}
alert('Please upload less than 1mb file');
return false;
});
//rest of your code
关于javascript - 返回false无效,但警报有效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31671491/