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