【问题标题】:change class of images via onError通过 onError 更改图像类别
【发布时间】:2014-11-21 10:23:39
【问题描述】:

在使用 JavaScript 和 HTML 时,如果图像来自损坏的 url,为什么不能改变图像的类别?

onError="this.style.display=\'none\';this.class=null;"

我也试过这个:

onError="this.style.display=\'none\';class=null;"

onError="this.style.display=\'none\';class='';"

什么能起作用?

【问题讨论】:

    标签: html class onerror


    【解决方案1】:

    尝试this.className 而不是this.classclass

    <img src="/abc.png" class="random" onError="this.style.display='none';this.className='';" />
    

    【讨论】:

    • 谢谢!!这样就解决了。对于这种特定的东西,我找不到任何参考:(哦,好吧。感谢您的解决方案。
    【解决方案2】:

    如果您想更改 css 类,您要查找的属性称为 className 而不是 class。所以你应该改变它。

    <img class='test' src="./lad" onError="this.style.display='none'; this.className=''">
    

    查看这个小提琴进行比较:http://jsfiddle.net/awbrpn99/

    【讨论】:

      猜你喜欢
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多