用js實現(xiàn)預(yù)覽待上傳的本地圖片
更新時間:2007年03月15日 00:00:00 作者:
<form name="form5" id="form5" method="post" action="#">
<input type="file" name="file5" id="file5" onchange="preview5()"/>
</form>
<script type="text/javascript">
function preview5(){
var x = document.getElementById("file5");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
var y = document.getElementById("img5");
if(y){
y.src = "file://localhost/" + x.value;
}else{
var img=document.createElement("img"); img.setAttribute("src","file://localhost/"+x.value);
img.setAttribute("width","120");
img.setAttribute("height","90");
img.setAttribute("id","img5");
document.getElementById("form5").appendChild(img);
}
}else{
alert("您選擇的似乎不是圖像文件。");
}}
</script>
<input type="file" name="file5" id="file5" onchange="preview5()"/>
</form>
<script type="text/javascript">
function preview5(){
var x = document.getElementById("file5");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
var y = document.getElementById("img5");
if(y){
y.src = "file://localhost/" + x.value;
}else{
var img=document.createElement("img"); img.setAttribute("src","file://localhost/"+x.value);
img.setAttribute("width","120");
img.setAttribute("height","90");
img.setAttribute("id","img5");
document.getElementById("form5").appendChild(img);
}
}else{
alert("您選擇的似乎不是圖像文件。");
}}
</script>
您可能感興趣的文章:
- 上傳圖片預(yù)覽JS腳本 Input file圖片預(yù)覽的實現(xiàn)示例
- JS預(yù)覽圖像將本地圖片顯示到瀏覽器上
- Javascript圖片上傳前的本地預(yù)覽實例
- javascript IE7 瀏覽器本地圖片預(yù)覽
- 詳解nodejs實現(xiàn)本地上傳圖片并預(yù)覽功能(express4.0+)
- 原生js FileReader對象實現(xiàn)圖片上傳本地預(yù)覽效果
- JS中利用FileReader實現(xiàn)上傳圖片前本地預(yù)覽功能
- vue.js 實現(xiàn)圖片本地預(yù)覽 裁剪 壓縮 上傳功能
- JS實現(xiàn)的input選擇圖片本地預(yù)覽功能示例
- 基于JavaScript實現(xiàn)本地圖片預(yù)覽
- JavaScript實現(xiàn)預(yù)覽本地上傳圖片功能完整示例
相關(guān)文章
關(guān)于JSON.parse(),JSON.stringify(),jQuery.parseJSON()的用法
下面小編就為大家?guī)硪黄P(guān)于JSON.parse(),JSON.stringify(),jQuery.parseJSON()的用法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06RGB轉(zhuǎn)換實現(xiàn)代碼,淘寶前端開發(fā)工程師筆試題
寫一個轉(zhuǎn)換RGB的值的函數(shù),實現(xiàn)以下效果。2010-11-11