Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在悬停顶部 DIV 后,我在获取放置在多个 DIV 中的最低元素(图像)的 ID 时遇到问题。这是我的结构:
<div id="dig-xx"> <div> <div>Content</div> <div><img src="some_picture.jpg" id="aig-xx" alt="" /></div> </div>
使用 id="dig-xx" 悬停整个 DIV 后如何获取 <img> ID?谢谢您的答复。
试试这个
$('#dig-xx').on('hover', function(){ var imgId = $(this).find('img').attr('id'); });
如果您有多个实例,则使用Attribute Starts with Selector
Attribute Starts with Selector
$('[id^="dig"]').on('hover', function(){ var imgId = $(this).find('img').attr('id'); });
检查小提琴