1
试图让一个简单的弹出出现在mouseover
a div
我跟着答案Description Box using "onmouseover",但它不起作用。我错过了什么?鼠标悬停弹出消息
<!DOCTYPE html>
<head>
<style>
.parent .popup {
display: none;
}
.parent:hover .popup {
display: block;
}
</style>
</head>
<body>
<script type="text/javascript">
var e = document.getElementById('#parent');
e.onmouseover = function() {
document.getElementById('popup').style.display = 'block';
}
e.onmouseout = function() {
document.getElementById('popup').style.display = 'none';
}
</script>
<div id="parent">
This is the main container.
<div id="popup" style="display: none">some text here</div>
</div>
</body>
</html>
有指问题上接受答案的评论,您需要使用ID选择不类的。另外,那里的答案告诉你,如果你使用CSS,则不需要JS –