網頁特效 上傳圖片前預覽(支援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>