问题
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();
});
});
bootstrap carousel markup
回答1:
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>
The 2000 value is in miliseconds.
来源:https://stackoverflow.com/questions/37728140/remove-bootstraps-carousel-item-if-image-not-found