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 –