gpt4 book ai didi

javascript - 使用 "onmouseover"的描述框

转载 作者:行者123 更新时间:2023-12-01 11:36:40 25 4
gpt4 key购买 nike

我在玩onmouseover javascript中的事件

我想弹出一个小框,直到没有onmouseover不再

我认为它被称为描述框,但我不确定。

当我将鼠标放在某些文本上时,如何让一个带有自定义文本的小框弹出,并在我将鼠标移动到另一个对象时消失..?

最佳答案

假设 popup是您的“描述框”的 ID:

HTML

<div id="parent"> <!-- This is the main container, to mouse over -->
<div id="popup" style="display: none">description text here</div>
</div>

JavaScript
var e = document.getElementById('parent');
e.onmouseover = function() {
document.getElementById('popup').style.display = 'block';
}
e.onmouseout = function() {
document.getElementById('popup').style.display = 'none';
}

或者,您可以完全摆脱 JavaScript,而只使用 CSS:

CSS
#parent #popup {
display: none;
}

#parent:hover #popup {
display: block;
}

关于javascript - 使用 "onmouseover"的描述框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3559467/

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