1 function getImgSrc(target, callback) { 2 if (window.FileReader) { 3 var oPreviewImg = null, oFReader = new window.FileReader(); 4 oFReader.onload = function (oFREvent) { 5 oPreviewImg = new Image(); 6 var type = target.files[0].type.split("/")[1]; 7 var src = oFREvent.target.result; 8 oPreviewImg.src = src; 9 10 if (typeof callback == "function") { 11 callback(oPreviewImg, target, type, src); 12 } 13 14 return oPreviewImg.src; 15 }; 16 17 return (function () { 18 var aFiles = target.files; 19 if (aFiles.length === 0) { 20 return; 21 } 22 if (!IsImgType(aFiles[0].type)) { 23 alert("You must select a valid image file!"); 24 return; 25 } 26 27 if (aFiles[0].size > 1024 * 1024) { 28 target.value = ""; 29 alert(‘Please upload image file size less than 1M.‘); 30 return; 31 } 32 33 oFReader.readAsDataURL(aFiles[0]); 34 })(); 35 } 36 if (navigator.appName === "Microsoft Internet Explorer") { 37 return (function () { 38 document.getElementById("imagePreview").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = target.value; 39 })(); 40 } 41 }
时间: 2024-11-09 04:44:40