js 验证图片

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); //化为可浏览地址
				}

  

posted @ 2018-06-20 09:25  DangerousBaymax  阅读(242)  评论(0编辑  收藏  举报