当用户点击class click_1时,我想要显示图像的路径。请注意,click_1发生在两种情况下。jquery选择器获取图像路径
<a href="#" class='click_1' ><img src="assets/img/shoe05.png" /></a>
<h4><a href="#" class='click_1' >title link 2</a></h4></li>
$('.click_1').click(function() {
var fullPath = $(this).children("img:first").attr('src');
if (typeof fullPath === "undefined"){
// this one does not work...
var fullPath = $(this).prev("img").children("img:first").attr('src');
console.log(fullPath);
}
}
所有很好的答案。这是最简单的。 –