如题:部分代码如下
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>
...为何有的图片能显示出来,有的不行啊,怎么改?
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>
...为何有的图片能显示出来,有的不行啊,怎么改?
在IE7,6下没问题,只是在IE8下不行
<%@ 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>
但是改成asp的下面那块,就没问题了,无论在那种浏览器下
是asp.NET里的什么,影响了错误?