2

无论如何,prettyphoto 中有没有让我将参数传递给回调函数

这是我目前的设置

<link rel="stylesheet" href="/css/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" />
<script src="/js/jquery.prettyPhoto2.js" type="text/javascript" charset="utf-8">

<script type="text/javascript" charset="utf-8">
  $(文档).ready(函数(){
    $("a[rel^='prettyPhoto']").prettyPhoto({
    回调:函数()
    {           
    $.post('/course/close-video', {topic_id: '13'});
    }
    });
  });
</脚本>


<a href="/course/play-video/topic_id/<?php echo $topic->topic_id;?>?iframe=true&width=470&height=340" rel="prettyPhoto" title="<?php echo $topic- >topic_name;?>">
<img src="/images/videos/" width="170" height="103" alt="topic_name;?>"/>
</a>

注意:我在回调中将主题值硬编码为 13 - 但这应该基于单击的链接。

页面中有多个这样的 a href 标签,每个标签都有一个唯一的 topic_id

那么如何将唯一的 topic_id 传递给回调函数

非常感谢

4

1 回答 1

4

我检查了源代码,Prettyphoto 不支持它。但是你可以修改 prettyphoto 的来源。

在版本 1.3.4(未压缩)中,您必须更改回调函数,以便它支持将单击的元素作为参数传递。

编辑:Acullty 我不会更改源代码,下次您必须升级 Prettyphoto 时,您必须再次进行更改。维护起来会很麻烦。

一种解决方案可能是跟踪单击的链接并保存它:

$(document).ready(function(){
    var lastClicked = null;
    $("a[rel^='prettyPhoto']").prettyPhoto({
    callback: function()
    {           
        if(lastClicked != null) {
                var topicid = lastClicked.data("topicid"); // lastClicked is your lastclicked link. So you can use whatever jQuery method on it..
                alert("topic: " + topicid); // The topic_id
                $.post('/course/close-video', {topic_id: '13'});
                lastClicked = null; // Set the last clicked to null 
        }
    }
    }).click(function (){
        lastClicked = $(this);
});

});​</p>

我为您创建了一个 jsfiddle,以便您可以测试:http: //jsfiddle.net/26L8w/

这不会处理内置的“移动到下一个”功能,因为它不会跟踪它。但是如果你想跟踪它,你可以附加 jQuery。

于 2012-03-15T15:17:31.667 回答