【问题标题】:How to hide an image by src attribute in IE?如何在 IE 中通过 src 属性隐藏图像?
【发布时间】:2019-12-13 16:01:17
【问题描述】:

我正在尝试查找具有以特定 url 开头的 src 的图像并将其隐藏。我可以做到,但它在 IE 上不起作用。

是否有这个 css 的版本(可能是 javascript)也适用于 edge 和 IE

img[src ^= "https://www.google"]{
  display: none;
}

【问题讨论】:

  • 选择器看起来不错。可能与^=之前和之后的空格有关

标签: javascript html css internet-explorer


【解决方案1】:

使用这个 CSS3 attribute selector:

img[src*="hideme"] {
        display: none;
    }

像往常一样,已知某些版本的 IE 存在 CSS3 属性选择器的错误。 SitePoint 参考很有用:Link

【讨论】:

    【解决方案2】:

    以下是使用 IE 11 和 MS Edge 浏览器版本 44 测试的示例。在这两种浏览器和其他浏览器中,代码都可以正常工作。

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    img[src*="i.postimg.cc"] {display: none;}
    </style>
    </head>
    <body>
    
    <img src="https://i.postimg.cc/13D5v67n/223.png" alt="Trulli" width="500" height="333">
    
    </body>
    </html>

    参考:

    Hide image of specific size, by CSS?(请参阅线程中接受的答案。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-15
      • 2016-09-25
      • 2018-10-24
      • 2013-04-02
      • 1970-01-01
      • 2011-10-09
      • 2021-08-05
      相关资源
      最近更新 更多