Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery:使用prev()获取上一个图像_Jquery_Image_Src - Fatal编程技术网

Jquery:使用prev()获取上一个图像

Jquery:使用prev()获取上一个图像,jquery,image,src,Jquery,Image,Src,我的问题是: $("#gallery > img").live('click',function() { $(this).prev().css("background" , "#f99"); // WORKS ! var src = $(this).prev().src; // DOESN'T WORK (src is undefined) }); 我在google chrome调试器中看到prev函数返回jQuery.fn.jQuery.in

我的问题是:

$("#gallery > img").live('click',function() {
    $(this).prev().css("background" , "#f99"); // WORKS !
    var src = $(this).prev().src;               // DOESN'T WORK (src is undefined)
});
我在google chrome调试器中看到prev函数返回jQuery.fn.jQuery.init[1]对象。。。它似乎包含了我想要的索引为0的prev的HTMLImageElement,但是像数组一样使用它是行不通的

我在这里迷路了我需要一些帮助。。。谢谢你们

// get the DOM element and access the src property
var src = $(this).prev()[0].src; 
或:

或:

// get the DOM element and access the src property
var src = $(this).prev().get(0).src; 
// access the src via .attr()
var src = $(this).prev().attr("src");