首页 文章

Prettyphoto - 如何将唯一参数传递给回调函数

提问于
浏览
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">
  $(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto({
    callback: function()
    {           
    $.post('/course/close-video', {topic_id: '13'});
    }
    });
  });
</script>


<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 - 但这应该是基于单击哪个链接而来的 .

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

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

非常感谢

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);
    });
    

    });

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

    这将无法处理内置的“移动到下一个”功能,因为它不会跟踪它 . 但是如果你想跟踪它,你可以使用jQuery .

相关问题