var selectedImg = e.target.files[0]; //获取图片var isPic = /^(image\/bmp|image\/gif|image\/jpeg|image\/png|image\/tiff)$/i; //验证正则if(selectedImg) {if(!isPic.test(selectedImg.type)) {alert(‘文件格式必须为图片‘);return;}if(selectedImg.size > 2097152) {alert("图片大小不能超过2M");return;}this.images = URL.createObjectURL(selectedImg); //化为可浏览地址}
js 验证图片
原文地址:https://www.cnblogs.com/DangerousBaymax/p/9202210.html