【发布时间】:2017-03-22 13:57:55
【问题描述】:
这是我的 html 代码,其中我有一个 div,并且在 div 之外有一个图像
<div runat="server" id="ProductThumbnail" style="width:140px;height:140px;position:relative;background-position:center;background-repeat:no-repeat;">
<asp:Image ID="ProductThumbnail1" runat="server" Style="max-height: 50px;position:absolute;right:0px;top:0px;" />
</div>
<asp:Image ID="Imagealt" runat="server" />
我正在做的是将服务器端的 div 背景图像设置为代码
ProductThumbnail.Style.Add("BACKGROUND-IMAGE", "url(" + Item.ThumbnailUrl.Replace("~", "..") + ")");
我想要的是,如果 div 背景图像 url 没有显示任何图像,那么 Imagealt 将显示我从后端设置的 alt 文本,如果 div 背景图像 url 在这种情况下显示图像 Imagealt隐藏起来
我希望所有这些都在服务器端代码和 javascript 上完成
**在左侧 div 图像不存在,因此图像替代文本显示是正确的,但在右侧图像显示仍然向下替代文本出现,这是错误的
如果显示 div 背景图像,我不想显示替代文本**
1-如果图片没有替代文字
2-如果图片未显示,则显示替代文字
例如:
如果我的div背景图片url路径设置为这个url
http://meenaprints.in/Admin/images/productimg/thumbnail/436x636_4736.jpg
不应出现替代文本,因为此 URL 正在检索图像
但是
如果div背景图片URL路径设置为URL
http://meenaprints.in/Admin/images/productimg/thumbnail/436x636_473123.jpg
不是检索图像而不是 ALT 文本应该得到显示
【问题讨论】:
-
图像没有显示...你能检查一下 div 背景看它指向的位置吗(我认为传递了错误的路径)
-
编写的代码是正确的,我只需要找到如果没有 dic 背景图像,它会显示 alt 文本的代码
-
所以代码是正确的......你没有任何问题......好:)
-
我需要为 div 何时显示图像图像替代文本不显示进行编码,如果 div 图像背景图像 url 错误,但明显的图像不会显示,在这种情况下,我需要图像替代文本获取展示
-
@Hackerman 请查看更新后的问题。希望你能得到我需要的东西