图片重载
来源:互联网 发布:python数据分析怎么样 编辑:程序博客网 时间:2024/05/21 11:03
图片加载失败显示默认图片
使用onerror事件
$('img').error(function(){ $(this).attr('src', "default.jpg(默认图片的url地址)");});
图片加载失败自动重试,重试失败显示默认图片
<body><img id="img" src="clock60.png" retry="0" ><script>$(function() { $('#img').on('error', function() { var retry= $('#img').attr("retry"); if (retry > 0) { $('#img').attr('src', 'https://iustudio.science/images/srpr/logo11w.png'); } else { retry++; $('#img').attr("retry", retry); $('#img').attr('src', $('#img').attr('src')); } });}) </script></body>
图片加载失败点击重试
<body> <img id="test" src="dist/img/contact/QRCod1e.jpg" data-loaded="true"></body?<script>// 图片图片是否加载成功,加载成功图片的data-loaded属性设置为true$(function(){ $('img').error(function(){ $(this).attr('data-loaded', 'false') }).click(function(){ if($(this).attr('data-loaded') === 'false'){ // 增加随机数让浏览器不从缓存读取图片 var src = 'dist/img/contact/QRCode.jpg?t=' + Math.random(); $(this).attr('src', src ) } }).load(function(){//如果加载成功重置图片状态 $(this).attr('data-loaded', 'true') })})</script>
阅读全文
0 0
- 图片重载
- 重载<<
- 重载
- 重载
- 重载
- 重载
- 重载()
- 重载
- 重载
- 重载
- 重载
- 重载
- “+ - * /”重载
- 重载
- 重载
- 重载
- 重载
- 重载
- H5加载音乐
- iOS视频压缩存储至本地并上传至服务器
- CentOS5.5 下搭建 PHP 环境(最佳的LAMP环境)
- leetcode-7 Reverse Integer
- 保存一份常用汉字的unicode码表范围
- 图片重载
- java提高篇(十三)-----字符串
- VERO.ALPHACAM.V2017.R2
- 根据值来动态选中select option
- Java操作redis
- 欢迎使用CSDN-markdown编辑器
- UDP局域网广播实现CS房间列表
- JAVAWEB开发之SpringMVC详解(二)——高级开发、数据回显、参数绑定集合、图片上传、json交互、validation校验、异常处理、RESTful支持、拦截器
- leetcode week18