隐藏或删除使用$(" img")找不到的图像.error(function()

时间:2016-10-16 18:28:11

标签: javascript jquery html fancybox fancybox-2

在我的页面中,我可以将图片暂时上传或删除,以便我找到可以删除或隐藏有关我的img src的警告的内容?

您可以在此处或此链接中查看我的代码 - >

http://www.booclin.ovh/tom/2/

这是我的代码



$("img").error(function() {
  $(this).parent().remove();
});

$("a.fancyboxgallery").fancybox();

<link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.js"></script>

<a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/6.jpg" title="">
<img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/06.jpg" alt=""/>
</a>
    
<a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/5.jpg" title="">
<img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/05.jpg" alt=""/>
</a>
    
<a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/4.jpg" title="">
<img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/04.jpg" alt=""/>
</a>
    

    
<a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/3.jpg" title="">
<img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/03.jpg" alt=""/>
</a>
    
<a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/2.jpg" title="">
<img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/02.jpg" alt=""/>
</a>
    
<a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/1.jpg" title="">
<img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/01.jpg" alt=""/>
</a>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

控制台中出现的错误:$ is not defined表示未加载jQuery。

您可以在<div class="rightpart">内的<body>内加载。

尝试在<head>之前的<script type="text/javascript" src="index/js/jquery.fancybox.js"></script>加载<html lang="en" class="js backgroundsize"><!--<![endif]--> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1, minimum-scale=1, maximum-scale=1.0"> <meta name="apple-mobile-web-app-capable" content="yes"> <link property="stylesheet" rel="stylesheet" type="text/css" href="index/css/style.css" class="--apng-checked"> <link property="stylesheet" rel="stylesheet" type="text/css" href="index/font/font.css" class="--apng-checked"> <link rel="stylesheet" type="text/css" media="screen" href="index/css/jquery.fancybox.css" class="--apng-checked"> <link rel="stylesheet" media="screen" href="index/js/jquery.fancybox.css" type="text/css" class="--apng-checked"> <script type="text/javascript" src="index/js/jquery.fancybox.js"></script> <script type="text/javascript" src="index/js/fancybox.js"></script> <style type="text/css" class="--apng-checked">.fancybox-margin{margin-right:0px;}</style> </head> <body> <div class="leftpart"> <a href="#">PROJECT</a> </div> <div class="rightpart"> <div id="globalgalerie"> <a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/3.jpg" title=""> <img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/03.jpg" alt=""> </a> <a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/2.jpg" title=""> <img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/02.jpg" alt=""> </a> <a class="fancyboxgallery" rel="book" href="http://www.booclin.ovh/tom/2/index/photos/projet/1.jpg" title=""> <img class="fancyboxthumbnailsgallery" src="http://www.booclin.ovh/tom/2/index/photos/projet/01.jpg" alt=""> </a> </div> </div> <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <script type="text/javascript" src="index/js/modernizr.custom.js"></script> <script type="text/javascript" src="index/js/jquery.fancybox.js"></script> <script type="text/javascript" src="index/js/fancybox.js"></script> <script type="text/javascript"> $("img").error(function() { $(this).parent().remove(); }); $("a.fancyboxgallery").fancybox(); </script> </body> </html>

修改

以下是您为实时链接的代码检查员复制的HTML:

<head>

所以我的意思是在<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <script type="text/javascript" src="index/js/modernizr.custom.js"></script> <script type="text/javascript" src="index/js/jquery.fancybox.js"></script> <script type="text/javascript" src="index/js/fancybox.js"></script> 部分中移动这些行:

<head>

这些已经在<script type="text/javascript" src="index/js/jquery.fancybox.js"></script> <script type="text/javascript" src="index/js/fancybox.js"></script> 中......无需复制它们。

<body>

launchWebAuthFlow

结束时您的错误功能正常