如题:部分代码如下
var ID=1
      function Addfun()
      {
        var newrow=Main_Table.insertRow(); //Main_Table是用于布局的表格,就是在表里动态添加图片
        var newcell=newrow.insertCell();
        var Pic_path=document.getElementById("TextBox1").value;  //路径从TextBox里取,不是直接来自file
        Pic_path="file:\/\/\/"+Pic_path.replace(/\\/g, '\/');
        
        newcell.innerHTML="<img id='Img"+(ID++).toString()+"' src='"+Pic_path+"'/>";
        
      }
      
        function PreviewImg(imgFile)
        {          
          document.getElementById("TextBox1").value=imgFile.value; //图片文件路径暂存到TextBox1,在Addfun()里调用,另还有他用
          
        }
...<body>
 <asp:Button ID="Button2" runat="server" onclick="Button2_Click" OnClientClick="return Addfun();" Text="添加" />
请选择图片:<input type="file" name="file" onchange="javascript:PreviewImg(this);">
</body>
...为何有的图片能显示出来,有的不行啊,怎么改?

解决方案 »

  1.   

    不是图片格式问题,同样是.jpg的,有的行,有的不行,路径也没问题啊,同目录下的图片么
      

  2.   

    加载的是本地图片,路径每次都输出了,没问题啊;
    在IE7,6下没问题,只是在IE8下不行
      

  3.   

    哎,改成纯html就没任何问题了下面是有问题的代码,在vs2008下,用了AJAX extensions控件,是我要的东西,汗汗
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="manage.aspx.cs" Inherits="_Default" %>
    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
    <!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 runat="server">
        <title>无标题页</title>
        <script type="text/javascript"> 
          var ID=1
          function Addfun()
          {
            var newrow=Main_Table.insertRow();
            var newcell=newrow.insertCell();
            var Pic_path=document.getElementById("TextBox1").value;
            Pic_path="file:\/\/\/"+Pic_path.replace(/\\/g, '\/');      
            newcell.innerHTML="<img id='Img"+(ID++).toString()+"' src='"+Pic_path+"'/>";       
            alert(newcell.innerHTML); //输出路径查看
            
          }
          
            function PreviewImg(imgFile)
            {          
              document.getElementById("TextBox1").value=imgFile.value;
              
            }
        </script></head>
    <body>    <form id="form1" runat="server">
        <div>
        <input type="file" id="file" style="display:none"/> 
            <table id="Main_Table" align="center" cellpadding="0" cellspacing="0" style="width:800px;">
                <tr>
                    <td>
                    
                        1
                    
                    </td>
                </tr>
                <tr>
                    <td>
                        56</td>
                </tr>
                <tr>
                    <td>
                        54</td>
                </tr>
            </table>
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
                      </asp:ToolkitScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                  <table id="mytable" align="center" width="800px"><tr><td>
           
                    请选择图片:<input type="file" name="file" onchange="javascript:PreviewImg(this);">
                      
                      </td></tr>
                      <tr>
                          <td>
                              <asp:TextBox ID="TextBox1" runat="server" Width="201px"></asp:TextBox>
                              <asp:Button ID="Button2" runat="server" onclick="Button2_Click" OnClientClick="return Addfun();" Text="添加" />
                              <asp:Button ID="Button3" runat="server" Text="删除" />
                              </td>
                      </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>        </div>
        
        </form>
    </body>
    </html>
    下面是没问题的,纯html的,不是我要的,试验偶然发现的
    <!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 runat="server">
        <title>无标题页</title>
        <script type="text/javascript"> 
          var ID=1
          function Addfun()
          {
            var newrow=Main_Table.insertRow();
            var newcell=newrow.insertCell();
            var Pic_path=document.getElementById("TextBox1").value;
            Pic_path="file:\/\/\/"+Pic_path.replace(/\\/g, '\/');
            
            newcell.innerHTML="<img id='Img"+(ID++).toString()+"' src='"+Pic_path+"'/>";
            
            alert(newcell.innerHTML);
            
          }
          
            function PreviewImg(imgFile)
            {          
              document.getElementById("TextBox1").value=imgFile.value;
              
            }    </script></head>
    <body>    <form id="form1" runat="server">
        <div>
        <input type="file" id="file" style="display:none"/> 
            <table id="Main_Table" align="center" cellpadding="0" cellspacing="0" style="width:800px;">
                <tr>
                    <td>
                        1           
                    </td>
                </tr>
                <tr>
                    <td>
                        56</td>
                </tr>
                <tr>
                    <td>
                        54</td>
                </tr>
            </table>        请选择图片:<input type="file" name="file" onchange="javascript:PreviewImg(this);"><br/>
            <input type="text" ID="TextBox1"  Width="201px"/>
            <input type="button" ID="Button2" value="添加"  OnClick="return Addfun();" />
                             
          </div>
        
        </form>
    </body>
    </html>
      

  4.   

    那我就不行了,这种ASP如果有问题的话那我不知道了
      

  5.   

    是asp.NET的,看第一块代码,是那里有问题
    但是改成asp的下面那块,就没问题了,无论在那种浏览器下
    是asp.NET里的什么,影响了错误?
      

  6.   

    请问这个问题解决了没有呢  我的是在jsp中 用img src=""  而有的图片显示有的图片不显示....