<!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=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">function yulan()
{
var fileext=document.form1.UpFile.value.substring(document.form1.UpFile.value.lastIndexOf("."),document.form1.UpFile.value.length);
fileext=fileext.toLowerCase();
if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
{
alert("上传图片类型错误!");
document.form1.UpFile.focus();
}
else
{
//alert(''+document.form1.UpFile.value);
document.getElementById("preview").innerHTML="<img src='"+document.form1.UpFile.value+"' id='cropTestImg'>" ;
}
} </script>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="UpFile" type="file" id="UpFile" onchange="yulan()" />
</form>
<div id="preview"></div>
<p> </p>
</body>
</html>
原来要修改:
工具 -> Internet选项 -> 安全 -> 自定义级别 -> 将本地文件上载至服务器时包含本地目录路径,选中启用即可
<p></p><img src="" id ="imgView" />
<script>
function setImg()
{
var isIE = document.all?true:false;
var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);
var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);
var upLoadImgFile = document.getElementById("upLoadImgFile");
debugger;
var imgView = document.getElementById("imgView");
if(isIE){
if(isIE7 || isIE8)
{
upLoadImgFile.select();
imgView.src = document.selection.createRange().text;
document.selection.empty();
}else{ imgView.src = upLoadImgFile.value;}
}else{
imgView.src = upLoadImgFile.files.item(0).getAsDataURL();
}
}
</script>