html
  <td colspan="2" style="width:600px; height:80px; "><img src="images/expand.jpg" id="Img"  runat="server"  style="width:500px; height:80px;"/></td>
            <td>&nbsp;<input type="button" id="fbt" class="fbt" onclick="fileup.click();" value="浏览" runat="server"/>
js
 function change(){
            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 file =document.getElementById("fileup");
            alert(file.value);
             if(isIE7 || isIE8)
             {
                file.select();
                var path=document.selection.createRange().text;
               
             }
                document.selection.empty();
                
                document.getElementById("Img").src=file.value;
               
          }
这样出来的路径是
怎么才能获得真实的路径来给img标签里的src?

解决方案 »

  1.   

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script>
    window.onload = function(){
    var img_src_1 = "http://www.baidu.com/img/baidu_sylogo1.gif"
    var img_1 = document.getElementById("aaa");
    img_1.src = img_src_1;
    }
    </script>
    </head><body>
    <img id="aaa">
    </body>
    </html>
    直接赋值就好了
      

  2.   

    主要是我想<input type="file"/> 标签里选择的图片来赋值给 img 。但是除IE外,其他浏览器都获取不了真实的路径,你有什么办法吗?
      

  3.   

    你得到就是它的真实路径。实际上,我猜测你是想要通过某些操作,将本地图片显示到页面上去,这个需要有个上传图片的操作,首先将图片上传到server端某个指定目录下,然后,再链接到页面上就简单了。
      

  4.   

    chrome,firefox等不行,ie才能使用selecttion,如果是预览的话IE,firefox可以参考这个:javascript实现IE,firefox客户端图片预览,chrome必须上传到服务器去返回服务器路径,要不无法显示本地文件的
      

  5.   

    能有具体点代码的吗 你那个我看过了  在chrome上还是不行
      

  6.   

    chrome浏览器无解,只能上传到服务器之后再进行预览
      

  7.   

    第一,chrome不可能取到文件的真实路径
    第二,chrome不可能将图片的src指向本地路径