当前位置: 代码迷 >> Java Web开发 >> 容易的js效果实现不了。
  详细解决方案

容易的js效果实现不了。

热度:3783   发布时间:2016-04-10 23:59:19.0
简单的js效果实现不了。。

初学js,一个简单的效果,就是鼠标移上去显示效果,鼠标拿开就效果隐藏,我也看不出我代码
有什么问题,能请教下各位吗

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>隐藏与显示</title>
<style type="text/css">
body{margin:0;padding:0;}
ul,li,div{margin:0;padding:0; list-style:none;}
ul{width:200px;margin:20px auto 0; background-color:#C63;}
ul li{width:200px;}
#list{display:none;}
ul li ul{margin:0;padding:0;}

</style>
<script type="text/javascript">
function show(idName){
document.getElementById(idName).style.display='block'
}

function hidden(idName){
document.getElementById(idName).style.display='none'
}

</script>
</head>

<body>
<ul>
     <li onmouseover="show('list')" onmouseout="hidden('list')">平面设计
         <ul id="list">
             <li>第一天</li>
                <li>第二天</li>
                <li>第三天</li>
            </ul>
        
        </li>
    
    </ul>
</body>
</html>

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>隐藏与显示</title>
<style type="text/css">
body{margin:0;padding:0;}
ul,li,div{margin:0;padding:0; list-style:none;}
ul{width:200px;margin:20px auto 0; background-color:#C63;}
ul li{width:200px;}
#list{display:none;}
ul li ul{margin:0;padding:0;}

</style>
<script type="text/javascript">
</script>
</head>

<body>
<ul>
     <li onmouseover="document.getElementById('list').style.display='block'" onmouseout="document.getElementById('list').style.display='none'">平面设计
         <ul id="list">
             <li>第一天</li>
                <li>第二天</li>
                <li>第三天</li>
            </ul>
        
        </li>
    
    </ul>
</body>
</html>

------解决方案--------------------
function hidden(idName){
document.getElementById(idName).style.display='none'
}

hidden换个名字
  相关解决方案