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");