我在上传图片前,想生成图片预览,在IE6下都可以实现,但在IE8下不行;在IE8下document.getElementById("file ").value得到的值 总是c:\fakepath+ 文件名,在IE8下如何能够得到它的实际值?不更改IE的设置,因为我不可能让每个使用此功能的人都更改自己的IE设置。
请各位高手指教。

解决方案 »

  1.   

    这里有一个图片上传预览效果
    支持ie和ff
      

  2.   

    本帖最后由 net_lover 于 2010-11-05 13:03:26 编辑
      

  3.   

    上传的时候,用户选择图片时,可以在资源管理器预览!
    个人认为还是上传成功后,预览服务器上的图片最好!如果非要本地预览:<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;
     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>// 非IE下面 getAsDataURL() 获取到的url 是加密的字符串,有几十k!!
      

  4.   

    谢谢各位兄弟的仗义,我用的是asp的代码,二楼的是c#的,暂时用不上,三楼的试了试,好像不行,一楼的可以,就是有些复杂。呵呵,不知还有没有别的方法?