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

无论如何我在prettyphoto中将参数传递给回调函数

这是我目前的设置

 
 

 
   $(文件)。就绪(函数(){
     $( “一个[相对^ = 'prettyPhoto']”)。prettyPhoto({
    回调:function()
     {           
     $ .post('/ course / close-video',{topic_id:'13'});
     }
     });
   });
 


 <a href="/course/play-video/topic_id/ topic_id;?>?iframe = true&width = 470&height = 340“rel =”prettyPhoto“title =” TOPIC_NAME;?>“>
 ”/>
 

注意:我已经在回调中将主题值硬编码为13 – 但这应该基于单击哪个链接来实现。

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

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

非常感谢

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

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

编辑:Acullty我没有改变源代码,下次你必须升级漂亮照片时,你必须再次进行更改。 这将是对维护的支持。

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

$(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/

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