gpt4 book ai didi

jquery - 使用 jQuery 获取 "img"id

转载 作者:行者123 更新时间:2023-11-28 04:08:02 24 4
gpt4 key购买 nike

我有这个代码:

<div id="popupContactIMG_4179" class="xxxx">
<a id="popupContactCloseIMG_4179">x</a>
<img alt="" src="../IMG_4179.jpg" id="id1">
</div>

我想得到 img<a>里面的id用鼠标点击 <a> :

$("a[id^=popupContactClose]").click(function(){ 
var qwerty = $(this+" img").attr("id");
}

有什么帮助吗?

最佳答案

最简单的方法是使用 next (因为 img 是以下同级):

$("a[id^=popupContactClose]").click(function(){ 
var qwerty = $(this).next().attr("id");
});

或者,您似乎试图做的是将 this 的父级作为上下文传递给 jQuery:

$("a[id^=popupContactClose]").click(function(){ 
var qwerty = $("img", $(this).parent()).attr("id");
});

关于jquery - 使用 jQuery 获取 "img"id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8923437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com