我有一个代码可以显示数据库中的事件信息。父容器的 id 是 show_id
。在 show_id
内部有一些隐藏的 div event_more_details
,其内容仅当我将鼠标悬停在父 div 上时显示,即 show_id
(在我的例子中我正在使用 mouseenter 功能)。这是代码:
$('.show_event').mouseenter(function(){
$('.event_more_details').fadeIn(500);
});
问题是,如果 php 生成五个事件,当我将鼠标悬停在一个事件上时,隐藏的 div 也会在所有其他父 div 中淡出。
最佳答案
如果我正确理解了您的 HTML 结构,您可以使用以下内容:
$('.show_event').mouseenter(function(){
$(this).siblings('.event_more_details').fadeIn(500);
});
.siblings()
将选择器应用于同级元素。 (docs)
关于php - 在鼠标输入php生成的内容时显示特定的子div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13549171/