1 function getPath(obj,fileQuery,transImg) 2 { 3 if(window.navigator.userAgent.indexOf("MSIE")>=1){ 4 obj.select(); 5 var path=document.selection.createRange().text; 6 obj.removeAttribute("src"); 7 obj.setAttribute("src",transImg); 8 obj.style.filter= "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale');"; 9 } 10 else{ 11 var file =fileQuery.files[0]; 12 var reader = new FileReader(); 13 reader.onload = function(e){ 14 obj.setAttribute("src",e.target.result) 15 } 16 reader.readAsDataURL(file); 17 } 18 }
1 var file_img=document.getElementById("up_user_img"); 2 var transImg; 3 getPath(file_img,this,transImg);
上述方法为一个完全兼容的版本
转载于:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3624132