<!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>&nbsp;</p>
</body>
</html>

解决方案 »

  1.   

    IE6下测试正常,换成IE8就不显示了
      

  2.   

    IE8中JS获得文件上传控件的路径不对,为:C:\fakepath\
    原来要修改:
    工具 -> Internet选项 -> 安全 -> 自定义级别 -> 将本地文件上载至服务器时包含本地目录路径,选中启用即可 
      

  3.   

    你说的不显示是文件流框没有  还是后面那个<div id="preview"></div>  这个不显示?
      

  4.   

    <input  type="file" id="upLoadImgFile" onchange ="setImg()"  /><input id="Submit1" type="submit" value="submit" />
    <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>
      

  5.   

    ie6以后的浏览器都不支持这个功能了,也就是说,ie7,ie8浏览器不能访问本地文件