為什么鼠標移開的時候 效果沒顯示
<!DOCTYPE html>
<html lang="en">
<head>
? ?<meta charset="UTF-8">
? ?<title>Title</title>
? ?<style>
? ? ? ?#nav{
? ? ? ? ? ?width: 200px;
? ? ? ? ? ?height: 250px;
? ? ? ? ? ?background: ?#cccccc;
? ? ? ?}
? ? ? ?#nav-a{
? ? ? ? ? ?width: 100px;
? ? ? ? ? ?height: 200px;
? ? ? ? ? background: ?#56c;
? ? ? ?}
? ? ? ?li{
? ? ? ? ? ?height: 20px;
? ? ? ? ? ?width: 20px;
? ? ? ? ? ?background: #000000;
? ? ? ? ? ?border: 1px solid #ffffff;
? ? ? ?}
? ? ? ?
? ?</style>
? ?<script type="text/javascript">
? ? ? ?window.onload=function() {
? ? ? ? ? ?var nav = document.getElementById('nav').getElementsByTagName('li');
? ? ? ? ? ?for(var i=0;i<nav.length;i++)
? ? ? ? ? ?nav[i].onmouseover = function () {
? ? ? ? ? ? ? changea();
? ? ? ? ? }
? ? ? ? ? nav[i].onmouseout=function () {
? ? ? ? ? ? ? changeb()
? ? ? ? ? }
? ? ? ?};
? ? ? ?function changea() {
? ? ? ? ? ?var aNav=document.getElementById('nav-a');
? ? ? ? ? ?aNav.style.display='none';
? ? ? ?}
? ? ? ?function changeb() {
? ? ? ? ? ?var aNav=document.getElementById('nav-a');
? ? ? ? ? ?aNav.style.display='block';
? ? ? ?}
? ?</script>
</head>
<body>
<div id="nav">
? ?<ul>
? ? ? ?<li></li>
? ? ? ?<li></li>
? ?</ul>
</div>
<div id="nav-a"></div>
</body>
</html>
2016-08-08
for循環下少了{}把后面這段包裹起來:
?????????nav[i].onmouseover = function () {
? ? ? ? ? ? ? changea();
? ? ? ? ? }
? ? ? ? ? nav[i].onmouseout=function () {
? ? ? ? ? ? ? changeb()
? ? ? ? ? }