繁体   English   中英

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

[英]Prettyphoto - how to pass unique parameter to the callback function

反正是在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>

注意:我已经在回调中将topic值硬编码为13,但这就是应该基于单击哪个链接的原因。

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

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

非常感谢

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

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

编辑:笨拙我不会更改源代码,下次您必须升级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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM