当前位置:网站首页>Handling of web page image loading errors
Handling of web page image loading errors
2022-07-28 04:58:00 【JINZI village grass】
In the website , There is often a situation , quite a lot picture Or because the image address itself points to an unknown address (404 Address ), Or because the image server itself failed to give img Return the correct picture file stream , It will lead to pictures error perhaps alt Information , If there is no corresponding img Set width and height , It will even affect the layout of the entire page , For the above problems , We can use the method of monitoring pictures error The event is then handled accordingly . Such as :
<img src=" Picture address " onerror="this.src=' Replace picture address '"/>According to normal logic , There will be no problem with the above processing , But it's easy to ignore a situation , That is, if the replacement image address does not exist , that onerror The code inside will be executed repeatedly , Until the picture is requested , If you can't ask all the time , That's equivalent to an endless cycle . Regarding this , Add a line of code to the above code
this.onerror=none;After performing the first image replacement , Cancel the of the picture error Event monitoring . If the above code is used jquery The implementation is as follows
$("img").each(function (index,ele) {
$(ele).one("error",function () {
$(this).attr("src"," Replace picture address ");
})
});use one The bound event will be executed only once , So there will be no dead cycle
边栏推荐
- Depth traversal and breadth traversal of tree structure in JS
- HDU 1522 marriage is stable
- Alibaba interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- 吉利AI面试题【杭州多测师】【杭州多测师_王sir】
- excel实战应用案例100讲(十一)-Excel插入图片小技巧
- MySQL(5)
- FPGA:使用PWM波控制LED亮度
- The difference between alter and confirm, prompt
- Dynamic SQL and paging
- [Sylar] framework chapter -chapter21- environment variable module
猜你喜欢

flink思维导图

Domain name (subdomain name) collection method of Web penetration

FreeRTOS learning (I)

Leetcode 18. sum of four numbers

Easycvr Video Square snapshot adding device channel offline reason display

Machine learning and deep learning -- normalization processing

MySQL(5)

Odoo action analysis (action.client, action.act_window, action.server)
![[Hongke technology] Application of network Multimeter in data center](/img/28/2ecc5a7a766454968819c7748fe48e.png)
[Hongke technology] Application of network Multimeter in data center

linux下安装mysql
随机推荐
Service object creation and use
The first artificial intelligence security competition starts. Three competition questions are waiting for you to fight
Artificial intelligence and RPA technology application (I) -rpa Hongji product introduction, designer interface function explanation
Improving the readability of UI layer test with puppeter
王爽汇编语言详细学习笔记三:寄存器(内存访问)
Have you learned the common SQL interview questions on the short video platform?
[Hongke technology] Application of network Multimeter in data center
[idea] check out master invalid path problem
Activation functions sigmoid, tanh, relu in convolutional neural networks
Do you know several assertion methods commonly used by JMeter?
Installing MySQL under Linux
Domain name (subdomain name) collection method of Web penetration
alter和confirm,prompt的区别
Visual studio 2019 new OpenGL project does not need to reconfigure the environment
全方位分析STEAM和创客教育的差异化
Summary and review of puppeter
(manual) [sqli labs27, 27a] error echo, Boolean blind injection, filtered injection
基于MPLS构建虚拟专网的配置实验
Wang Shuang assembly language detailed learning notes 3: registers (memory access)
提升学生群体中的STEAM教育核心素养