首页
IT
登录
6mi
u
盘
搜
搜 索
IT
图片错误处理函数,基于joomla
图片错误处理函数,基于joomla
xiaoxiao
2021-03-25
60
<
script
>
function
imgErrorHandling
(local_base_host, local_base_path, server_path)
{
var
regexp =
new
RegExp
(
"^(.*"
+ local_base_host +
")|^("
+ local_base_path +
")"
);
//img图片错误处理
jQuery(
"img"
).error(
function
()
{
var
img_src, _this = jQuery(
this
), self_src = _this.attr(
"src"
); img_src = self_src.replace(regexp, server_path);
if
(!_this.hasClass(
"img-error"
)) { _this.addClass(
"img-error"
); _this.attr(
"src"
, img_src); } });
//背景图片错误处理
jQuery(
"[style^='background']"
).each(
function
()
{
var
bg_src, bgSelf_src = jQuery(
this
).css(
"background-image"
); bg_src = bgSelf_src.replace(regexp, server_path); jQuery(
this
).css(
"background-image"
,
'url("'
+ bg_src); }); } jQuery(document).ready(
function
()
{
var
test_host =
"192.168.0.100"
, test_path =
"/baidu"
, server_path =
"//www.baidu.com"
;
if
(window.location.host === test_host) { imgErrorHandling(
"//"
+ test_host + test_path, test_path, server_path); } });
</
script
>
转载请注明原文地址: https://ju.6miu.com/read-39014.html
技术
最新回复
(
0
)