1

任何人都知道如何通过带有 Jquery prettyPhoto 的 changepicturecallback 函数检索当前图像数据(alt、src)?

我想将这两个变量传递给 ajax 脚本,但我似乎无法掌握要传递的信息。试过这个无济于事。

    var image = jQuery(".pp_pic_holder").find("#pp_full_res img").attr("src");      

必须有一种方法可以在运行时轻松访问这些数据。有什么建议或指向正确的方向吗?

当我与 Gallerific 合作时,我能够使用

var image_src = this.data[nextIndex].slideUrl;

编辑 => 只需要缩小我对目标的搜索范围

        var image = jQuery('#fullResImage').attr('src');

现在工作得很好。

4

1 回答 1

3

从技术上讲,您的尝试是正确的,但请尝试扩大您的范围,并进行一些测试...

myCallbackTest = function() {
  alert('the callback worked! thats a good start!');

  var $activeimage = $("#fullResImage");

  var source = $activeimage.attr('src'), altText = $activeimage.attr('alt');

  if(!$activeimage.length) {
    alert('The image selector failed');
  } else if (!source) {
    alert('The image selector worked, but I found no source');
  } else if (!altText) {
    alert('Found The image and its source, but it doesnt seem to have any alt text');
  } else {
    alert('i got it! alt: ' + altText + ' src: ' + source);
  } 
}

那就试一试吧...

$(function() {
  $('a[rel^=prettyPhoto]').prettyPhoto({
    theme: 'facebook',
    slideshow:5000, 
    autoplay_slideshow:true,
    changepicturecallback: myCallbackTest
  });
});
于 2012-03-27T00:38:54.757 回答