这是HTML代码
<div id="_navigation">
<ul>
<li>Destinations</li>
<li><a href="HtmlPage.html">Culture</a></li>
<li><a href="HtmlPage.html">Adventure</a></li>
<li><a href="HtmlPage.html">Hotels</a></li>
<li><a href="HtmlPage.html">Wild Life</a></li>
<li><a href="HtmlPage.html">History</a></li>
<li><a href="HtmlPage.html">About</a></li>
</ul>
<div id="_subNavigation">
<div id="_navigationFirst">
this is first subnavigation it must be showed when user clicks on Distinations
</div>
<div id="_navigationSecond">
this is second subnavigation it must be showed when user clicks on Culture
</div>
<div id="_navigationThird">
this is third subnavigation it must be showed when user clicks on Adventure
</div>
</div>
</div>
我在它之后应用了一些CSS,看起来像这样 忘记CSS中的其他东西...... 在id为_subNavigation的CSS div中设置display:none; 使用java脚本我希望当有人点击目的地时,然后_navigationFirst(它是一个id)可见,当用户将鼠标移出导航区域时,它会熄灭(变得不可见)。 当用户点击它时,我成功地使它可见但是当用户将鼠标移出导航区域时它不会消失。这是我的javascipt
当我点击目的地时,我得到了这样的图像
"use strict";
document.getElementById("_navigation").getElementsByTagName("ul")[0].getElementsByTagName("li")[0].onclick = function () {
console.log("got into block");
document.getElementById("_navigationFirst").style.display = "block";
}
document.getElementById("_navigation").onmouseleave = function () {
console.log("you left _navigation block");
document.getElementById("_navigationFirst").style.display = "none";
}
那么 CodeGurus哪里错了?以及如何获得我想要获得的效果
答案 0 :(得分:0)
document.getElementById("_navigation").onmouseout = function () {
console.log("you left _navigation block");
document.getElementById("_navigationFirst").style.display = "none";
}
将其更改为“onmouseout
”。我不确定“onmouseout”是你想要的效果。你可以看看the difference between onmouseleave and onmouseout。如果你需要“onmouseleave”效果,你必须依赖jquery,因为javascript没有“onmouseleave”的内置支持。工作fiddle就在这里。