用文字代替破碎的图像图标

Replace broken image icon with text

本文关键字:图像 图标 破碎 文字      更新时间:2023-09-26

我想隐藏或删除破碎的图像图标,每当它弹出并替换为文本,读:"错误与图像。"现在,我有一些jQuery可以隐藏坏掉的图像图标,但我不能这样设置和显示所有文本。我是否需要有一个替代图像或有一种方法来显示文本,每当一个破碎的图像图标被隐藏?

这是jQuery代码:
<script type="text/javascript">
    $(document).ready(function () {
        $("img").error(function () {
            $(this).hide();
        })
    .attr("src", "error with image");
    });
</script>

这些是表中用来显示图像缩略图的字段:

<asp:ImageField HeaderText="Line dwg Thumb" DataImageUrlField="LineDrawThumbnail" NullDisplayText="error with image"  ControlStyle-Width="75px" ItemStyle-HorizontalAlign="Center">
 </asp:ImageField>
 <asp:ImageField HeaderText="Profile Thumb" DataImageUrlField="ProfileThumbnail" NullDisplayText="error with image" ControlStyle-Width="75px"  ItemStyle-HorizontalAlign="Center">
  </asp:ImageField>           

重要的边注:具有缩略图图像的数据库表没有任何Profile thumbnail或Line Draw thumbnail的空字段——只是碰巧有时缩略图还不存在。

您的脚本非常好,您需要做的就是在隐藏图像后添加文本

<script type="text/javascript">
    $(document).ready(function () {
        $("img").error(function () {
            $(this).hide();
        })
    .after('<p>error with image</p>');
    });
</script>