<asp:Image ID="photoimg" runat="server" />
                    <asp:FileUpload ID="photoupload" runat="server" Style="margin-left: 4px" Width="50px"
                        onchange="Preview(this.value);" onblur="checkoname(photoupload,show1)" />
        function Preview(imgSrc) {
           
                        var aa = imgSrc.toLowerCase().split('.');
                        alert(aa[aa.length - 1]);
                        if (aa[aa.length - 1] == 'gif' || aa[aa.length - 1] == 'jpg') {
                            show1.innerHTML = "";
                            if (imgSrc.fileSize / 1024 > 1024) {
                                show1.innerHTML = "图片太大请重新选择!"
                                return false;
                            } else {
                                show1.innerHTML = "";
                                document.getElementById("photoimg").src = imgSrc;
                                alert(document.getElementById("photoimg"));
                                return true;
                            }
                        }
                        else {
                            show1.innerHTML = "图片格式不正确";
                            return false;
                        }
        }
能读取路径 但是我在页面中更改FileUpload的文件时图片却不显示

解决方案 »

  1.   

    你fileUpload是服务器控件,换成HTml控件试试,
    还有你调试下
    alert(document.getElementById("photoimg"));
    里面返回什么值
      

  2.   

    你写的肯定出不来document.getElementById("photoimg").src = imgSrc;
    你这样可以获取到么?还有就是你要搞清楚服务器端和客户段得路径是不一样的,“~/”和"../".
    其实比较简单的就是 你只获取图片名 photoupload.filename;然后再拼字符串
    还有一点就是你的js是在客户段执行的,你getElementByid的应该是客户端的id,你执行程序,右键查看源码 看看id还是不是“photoimg”了。应该这样写getElementByID("<%=photoimg.ClientID%>").给你说了这么多了 ,你的问题应该能够解决了。
      

  3.   

    document.getElementById("photoimg").src = imgSrc; alert(document.getElementById("photoimg").src)路径是正确的 就是图片显示不出来 而且源码中的ID也是photoimg
      

  4.   

     <img id="photoimg" src="" />
                        <input type="file" name="photoupload" id="photoupload" onchange="Preview(this.value);" onblur="checkoname(photoupload,show1)" style="width:50px;margin-left: 4px" />

    这是源码
      

  5.   

    不是路途问题,是你用法错误了
    正确是document.getElementById('<%=photoimg.ClientID%>').src = imgSrc;