javascript - 无法读取未定义的属性 'match' - PrettyPhoto

标签 javascript jquery prettyphoto

我正在使用prettyPhoto当点击图像时,它显示正在加载 gif,但图像未加载。我在浏览器控制台上发现了此错误。

Uncaught TypeError: Cannot read property 'match' of undefined
    at h (jquery.prettyPhoto.js:7)
    at HTMLDivElement.<anonymous> (jquery.prettyPhoto.js:7)
    at HTMLDivElement.r.complete (jquery-1.10.2.min.js:5)
    at c (jquery-1.10.2.min.js:3)
    at Object.fireWith [as resolveWith] (jquery-1.10.2.min.js:3)
    at l (jquery-1.10.2.min.js:5)
    at x.fx.tick (jquery-1.10.2.min.js:5)

我该如何解决这个问题?

更新

我发现了这个问题。该图像位于 anchor 标记内。如果我使用 $("div.news-text-detail a").prettyPhoto(); 图像正在加载。这将对所有 anchor 标记应用效果。但我需要将其应用于 anchor 标记内的ONLY图像。

$(document).ready(function() {
        $("div.news-text-detail img").prettyPhoto();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/prettyPhoto/3.1.6/js/jquery.prettyPhoto.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prettyPhoto/3.1.6/css/prettyPhoto.min.css" rel="stylesheet"/>

<div class="news-text-detail span12">
   <div style="text-align: justify;">
      <div class="separator" style="clear: both; text-align: center;">
         <a href="http://i.imgur.com/mV7ezeo.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
            <img border="0" src="http://i.imgur.com/mV7ezeo.jpg" data-original-height="384" data-original-width="800" height="305" width="640">
         </a>
      </div>
   </div>
</div>

最佳答案

不确定我是否真的理解你的问题,但只有当它们包含 img 时,你才需要对 a 链接进行漂亮的拍照,对吗?

所以我想你可以这样做:

jQuery('div.news-text-detail img).closest('a').prettyPhoto();

首先你看img,然后你得到他的 parent a和a上的漂亮照片。

关于javascript - 无法读取未定义的属性 'match' - PrettyPhoto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45251875/

相关文章:

javascript - 使用 jQuery 将 div 动画移出窗口/ View ,调整大小时忽略 css 规则

javascript - 将选项值附加到隐藏字段?

javascript - 以 formatCurrency 取消货币全局化

javascript - 使用返回函数sinde .attr()jquery元素

javascript - PrettyPhoto - 如何在用户关闭模态框时进行跟踪

javascript - ExpressJS 安装

javascript - Angular/JavaScript无法识别函数内的全局变量

javascript - 无法使用 process.env 访问 react 环境变量

javascript - Reactjs中如何获取带有请求参数的完整路径?

javascript - 如何在 prettyPhoto Image Viewer 中设置缩略图