[转]文件浏览直接显示[兼容IE,FireFox]
转自:http://www.cnblogs.com/shawker/archive/2009/03/27/1423386.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script>
function $(o) {
return document.getElementById(o);
}
function SeePic(img,f){
var i = $(img);
var f = $(f);
if (f.value != "") {
if (f.value.indexOf("http://") >= 0) {
i.src = f.value;
} else {
if (!window.event)
{
var data = f.files.item(0).getAsDataURL();
i.src = 'data:' + data;
}
else
i.src = 'file:///'+f.value;
}
i.style.display = "block";
return;
}
i.style.display = "none";
}
</script>
</head>
<form id='frm1' name='frm1'>
<div><input type='file' name='upfile' id='upfile' onChange="SeePic('img', 'upfile');"></div>
<div><image src='' id='img' name='img' style="display:none;"> </div>
</form>
</body>
</html>
保存成utf-8格式,直接运行即可。