js 上傳圖片前預覽(支援ie7,ie8,firefox)

來源:互聯網
上載者:User
關鍵字 網頁製作 Ajax JavaScript

網頁特效 上傳圖片前預覽(支援ie7,ie8,firefox)

<head>
<meta HTTP-equiv="content-type" content="text/html; charset=gb2312" />
<title> 網頁特效 上傳圖片預覽</title>
<script language="網頁特效">
function showimage(fileuploadid, imgid) {
 & nbsp;  if (document.getelementbyid(fileuploadid).value != "") {
        document.getelementbyid(imgid).style.display = "block"
        document.getelementbyid(imgid).src = getpath(document.getelementbyid(fileuploadid));
    }
 }
 
 function getpath(obj) {
    if (obj) {
         if (window.navigator.useragent.indexof("msie") >= 1) {
             obj.select(); return document.selection.createrange().text;
        }
        else if (window.navigator.useragent.indexof("firefox") >= 1) {
             if (obj.files) { return obj.files.item(0).getasdataurl(); }
            return obj.value;
        }
         return obj.value;
    }
 }

</script>
</head>

<body>
<form enctype="multipart/form-data">
<label>
<input type="file" name="file" id="fid"  onmouseo教程ut="showimage('fid','viewimg');" >
</label>
<input name="" type="button" value="提交">
</form>
<img src="" id="viewimg">
</div>
</body>
</html>
代碼二

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> new document </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<script language="網頁特效">
<!--
function showimg(obj){
var imgobj = document.getelementbyid("imgid");
imgobj.src = obj.value;
}
-->
</script>
</head>

<body>
<input type="file" onchange="showimg(this)"><br>
<img src="" id="imgid"/>
</body>
</html>
//代碼三

<html>      
<head>      
<meta HTTP-equiv="content-type" content="text/html; charset=gb2312">      
<title>帶有圖片預覽功能的上傳表單--111cn.net</title>       
<script>      
function viewmypic(mypic,imgfile) {       
if (imgfile.value){        
mypic.src=imgfile.value;       
mypic.style.display="";       
mypic.border=1;        
}       
}        
</script>      
</head>       
<body>      
<center>      
<form >      
< input name="imgfile" type="file" id="imgfile" size="40" onchange="viewmypic(showimg,this.form.imgfile);" />       
<br />      
</form>       
<img name="showimg" id="showimg" src="" style="display:none;" alt="預覽圖片" /> & nbsp;    
<br />      
</div>       
<div style="display:none">      
</div >      
</center>      
</body >      
</html>
 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.