gpt4 book ai didi

javascript - 图像中的背景颜色(firefox)

转载 作者:太空宇宙 更新时间:2023-11-03 21:53:24 27 4
gpt4 key购买 nike

我做了类似的事情来处理丢失的图像并用背景颜色替换它

<td width="34"><img onError="handleError(this, '#fff', 'fail');" src="'. $profileImg .'" alt="" height="'.$imgHeight.'" /></td>

这就是处理该问题的 Javascript 函数:

      function handleError(elem, colorCode, state){
if ((typeof(elem.onerror) === 'function' && state === 'fail') || (elem.width === 0) ){
elem.style.backgroundColor = colorCode;
console.log(colorCode);
}
}

console.log 行显示 firefox 进入那里但不会显示背景颜色......

PS:我也试过使用 JQuery..

我做错了什么?

最佳答案

您的图片有 alt=""这意味着如果出现错误,它根本不会在标准模式下显示:图像就像 <span> 一样。在标准模式下使用 alt 文本。

关于javascript - 图像中的背景颜色(firefox),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15611239/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com