我希望当用户点击.fa-search-plus
时,警告会显示.img-reponsive
这是我的代码:
<div class="col-lg-push-4 col-lg-3 col-md-3 col-sm-12 col-xs-12">
<div class="grid">
<figure class="effect-hera">
<img class="img-responsive second"src="images/book4.png" data- toggle="modal" data-target="#myModal">
<figcaption>
<p>
<a href="imageideas.org/pdf/4.pdf"><i class="fa fa-download"></i></a>
<a data-toggle="modal" data-target="#myModal"><i class="fa fa-search-plus"></i></a>
</p>
</figcaption>
</figure>
</div>
</div>
<script>
$(".fa-search-plus").click(function(){
alert ($(this).parent().parent().find('.img-responsive').attr('src'));
})
</script>
答案 0 :(得分:1)
使用此代码可能对您有所帮助:
var someimage = document.getElementById('this_one');
var myimg = someimage.getElementsByTagName('img')[0];
var mysrc = myimg.src;
答案 1 :(得分:0)
使用jQuery的.closest()方法
$(".fa-search-plus").click(function(){
alert ($(this).closest('.effect-hera').find('.img-responsive').attr('src'));
});
或者您也可以使用parent()
$(".fa-search-plus").click(function(){
alert ($(this).parents('.effect-hera').find('.img-responsive').attr('src'));
});