浏览器中预览即将上传的图片

$("input[type=file]").on("change", function(){
	if( /^.+\.(jpg|jpeg|png)$/.test(this.value) ){
		var r = new FileReader(),
			name = this.name;
		r.onloadend = function(e){
			$("img[for="+name+"]").attr("src", e.target.result).addClass("loadend");
		};
		r.readAsDataURL(this.files[0]);
	}else{
		this.value = "";
		alert("仅支持(jpg、png)格式图片!");
	}
});