jquery 限制 input multiple上传文件大小

<input type="file" name="my_image_upload[]" id="my_image_upload" multiple="multiple" accept="image/*" required="required" />
 

var obj_file= $("#my_image_upload");
var length = obj_file[0].files.length;
var items = obj_file[0].files;
var fileSize = 0;

if (length > 0) {

for (var i = 0; i < length; i++) {

fileSize = fileSize+items[i].size; // get file size

}

if(fileSize > 1024*400) {

alert('图片不得大于500KB!');

// 清空input数据
$('#my_image_upload').val('');

}

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注