【问题标题】:Cannot read property 'match' of undefined - prettyPhoto无法读取未定义的属性“匹配” - prettyPhoto
【发布时间】:2025-12-30 15:55:11
【问题描述】:

我正在使用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)

我该如何解决这个问题?

更新

我发现了这个问题。图像位于锚标记内。如果我使用 $("div.news-text-detail a").prettyPhoto(); 图像正在加载。这将对所有锚标签应用效果。但我需要将此应用于 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>

【问题讨论】:

  • 我们需要您的代码来帮助...这是一个通用的 js 错误,对此无能为力。做一个sn-p。
  • 什么是 imageanchor ?你说它在你的代码中有意义,但我不明白为什么。你能在 sn-p 中添加一些 CSS 以便我们看到它完整吗?

标签: javascript jquery prettyphoto


【解决方案1】:

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

所以我想你可以这样做:

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

首先你看img,然后你在a上得到他的父母a和prettyphoto。

【讨论】:

  • 谢谢。这就是我要找的。​​span>
最近更新 更多