澳门鸿运国际,让你建站更便捷和轻松!
您当前的位置:鸿运娱乐 > 网页制作 > Javascript/Ajax
js 上传图片前预览(支持ie7,ie8,firefox)
来源:澳门鸿运国际  时间:2010-07-11 14:28:14

网页特效 上传图片前预览(支持ie7,ie8,firefox)

<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>网页特效 上传图片预览</title>
<script language="网页特效">
function showimage(fileuploadid, imgid) {
    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="预览图片" />      
<br />      
</div>      
<div style="display:none">      
</div>      
</center>      
</body>      
</html>
 

责任编辑:admin

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
CopyRight 2008-2009, favnav.com, Inc. All Rights Reserved
皖ICP备09015033号