本文實(shí)例講述了js實(shí)現(xiàn)上傳圖片預(yù)覽的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
if(document.all)//IE
{
imgFile.select();
path = document.selection.createRange().text;
document.getElementById("imgPreview").innerHTML="";
document.getElementById("imgPreview").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=/"" + path + "/")";//使用濾鏡效果
}
else//FF
{
path = imgFile.files[0].getAsDataURL();
document.getElementById("imgPreview").innerHTML = "<img id='img1' width='120px' height='100px' src='"+path+"'/>";
// document.getElementById("img1").src = path;
}
}
}
調(diào)用:
<div id="imgPreview" style="width:120px; height:100px;margin-left: 280px;">
</div>
運(yùn)行效果如下圖所示:

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注