代碼如下 複製代碼 代碼如下: 無標題文件 <BR>//本地圖片預覽<BR>function setImagePreview(fieldupload, image, imagediv) { <BR>var docObj = document. getElementById(fieldupload); <BR>var imgObjPreview = document.getElementById(image); <BR>if (docObj.files && docObj.files[0]) { <BR>/////////////////遇到圖圖當狐屬性imgObjPreview.style.display = 'block'; <BR>imgObjPreview.style.width = '150px'; <BR>imgObjPreview.style.height = '150px'; <BR>///filegOb.Previewbj. ].getAsDataURL(); <BR>//火狐7以上版本不能用上面的getAsDataURL()方式獲取,需要一下方式<BR>imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]); <BR>} else { <BR>//IE下,使用濾鏡<BR>docObj.select(); <BR>var imgSrc = document.selection.createRange().text; <BR>var localI.get (imagediv); <BR>//必須設定初始大小<BR>localImagId.style.width = "150px"; <BR>localImagId.style.height = "150px"; <BR>//圖片異常的捕捉,防止使用者修改後綴來偽造圖片<BR>try { <BR>localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)"; localImagId.filters.item("DXImageTransform.AlphaImage. src = imgSrc; <BR>} catch (e) { <BR>alert("您上傳的圖片格式不正確,請重新選擇!"); <BR>return false; <BR>} <BR>imgObjPreview.style .display = 'none'; <BR>document.selection.empty(); <BR>} <BR>return true; <BR>} <BR>