如果找不到图片,请删除Bootstrap的轮播项目 [英] Remove Bootstrap's Carousel item if image not found

查看:183
本文介绍了如果找不到图片,请删除Bootstrap的轮播项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当页面加载时,如果图像返回404 not found错误,我想删除包装的div.item,这样轮播就好像继续..如何实现此目的?

when the page loads, if the image returns a 404 not found error I would like to remove the wrapping div.item so the carousel continues as if.. how can I achieve this?

这是我的逻辑..但是没有运气

this was my logic.. but no luck

$(window).load(function() {
    $(".item img").error(function () { 
        $(this).parent('div.item').remove();
    });
});

引导轮播标记

推荐答案

在图片标签上,您可以添加onerror事件

On the image tag you can add the onerror event

<img src="404imagegoeshere" onerror="functionToRemoveWrapping(this)">

然后在您的函数上可以执行以下操作

Then on your function you can do something like this

    <script>
         function functionToRemoveWrapping(image) {
           setTimeout(function(){
             $(image).parent().remove;
           }, 2000);    
         }
    </script>

2000的值以毫秒为单位.

The 2000 value is in miliseconds.

这篇关于如果找不到图片,请删除Bootstrap的轮播项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆