如何在wordpress中使用jquery获取图像的URL?

时间:2013-05-23 10:28:36

标签: php jquery jquery-plugins wordpress-plugin wordpress

我正在开发一个小型灯箱wordpress插件,如果用户点击图像,图像应该出现在灯箱中。如何识别用户点击的图像的URL,因此在灯箱中显示图像非常有用。这可以在jquery中完成吗?有人可以帮忙吗?

2 个答案:

答案 0 :(得分:4)

你可以这样做

$("img").click(function() {
    var img_path = $(this).attr('src');
})

修改

变化

data: dataString,

data: 'img_path='+img_path,

您将能够像这样访问lightbox.php中的图像路径

$image_path = $_POST['image_path'];

答案 1 :(得分:1)

获取图片网址很简单。

$(function() {

  $('img').on('click', function( event ) {
    var source = this.src;    
    console.log( source );
  });

});