如何在<img src='getImg.aspx?plucode=<%#Eval("plucode")%>&&ImagLx=1&&ImagDx=1' alt='<%#Eval("pluname")%><%#Eval("Spec")%>' />这里做一个判断,在载入网页时显示默认图片。不知道为什么,每次打开网页 图片都不能全部显示出来,我想做一个默认图片显示,不然就是一个小叉很不友善,请问要怎么做啊?
调试欢乐多
Response.BinaryWrite(IO.GetAllBytes("默认图片路径"))
假设有一些情况无论处理,如getimg.aspx?id=1
id=1的记录删除了,你也应该提供一个默认的图片,即id=1的记录不存在,你就提供默认图片
解决的另一个办法是这样, 这个办法不推荐
<img src="http://www.163.com/1.gif" onerror="this.src='http://avatar.profile.csdn.net/B/C/6/2_goddrf.jpg'" />浏览器加载src的图片时,如果出现错误,则执行onerror事件,这个事件中赋于该img标签一个新的图片
可能你的getimg.aspx程序有问题啊,getimg.aspx里面每次读取的只是一条记录,不要多取
另外,可能你的网络环境有问题,跟你的isp可能有关系,这个问题可以直接读取物理文件测试
<script>
function LoadImage()
{
document.getElementById("img1").src=document.getElementById("img1").getAttribute("bigImage")
}
</script>
<img id="img1" src="本地图片" bigImage='getImg.aspx?plucode=<%#Eval("plucode")%>&&ImagLx=1&&ImagDx=1' alt='<%#Eval("pluname")%><%#Eval("Spec")%>' />
我试过了是可以的,但是我的图片是从repeater里面循环取出来的,你的方法像只能显示一张图片
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<img id="Img<%#Container.ItemIndex %>" src="" bigimage="<%#Eval("Img") %>" />
</ItemTemplate>
</asp:Repeater>
</form>
<script>
var count = <%=Repeater1.Items.Count %>;
window.onload=function()
{
for(i=0;i<count;i++)
document.getElementById("Img" + i).src=document.getElementById("Img" + i).getAttribute("bigImage")
}
</script>
</body>
</html>