今天终于写完了一个 可以水平下拉菜单和垂直下拉菜单之间随意切换的网页换肤程序,它综合应用了水平下拉菜单,垂直下拉菜单,网页换肤等技巧.
这个程序需要用到三个文件,一个是h.css,用作水平下拉菜单的样式文件,另一个是v.css,用作垂直下拉菜单的样式文件,最后一个就是包含下拉菜单内容的网页文档test.html.
test.html文件内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script>
function startlist()
{
if(document.all)
{
var navRoot = document.getElementById("nav");
for(var i=0;i<navRoot.childNodes.length;i++)
{
node = navRoot.childNodes[i];
if(node.nodeName == "LI")
{
node.onmouseover = function(){this.className = "hover";};
node.onmouseout = function(){this.className = "";};
}
}
}
}
window.onload = startlist;
function changeSkin()
{
var pathName = document.getElementById("cssfile").href;
var fileName = pathName.substring(pathName.lastIndexOf("/")+1);
document.getElementById("cssfile").href = (fileName=="h.css"?"v.css":"h.css");
}
</script>
<link rel="stylesheet" type="text/css" href="h.css" id="cssfile"/>
</head>
<body>
<ul id="nav">
<li>java培训
<ul>
<li>java基础提高</li>
<li>java就业实战</li>
<li>java高手精华</li>
</ul>
</li>
<li>.net培训
<ul>
<li>.net基础提高</li>
<li>.net就业实战</li>
<li>.net高手精华</li>
</ul>
</li>
<li><a href="#" onclick="changeSkin()">切换样式</a></li>
</ul>
<div id="content">
内容区
</div>
</body>
</html>
h.css文件内容:
#content {clear:both;}
ul {
list-style:none;
margin:0px;
padding:0px;
}
li{
margin:0px;
padding:0px;
float:left;
width:100px;
height: 20px;
border:1px solid #ddd;
position: relative;
}
li ul{
background-color:#eee;
display:none;
top:20px;
left:0px;
position:absolute;
}
li:hover,li.hover {background-color:#eee;}
li:hover,li.hover ul{
display:block;
}
v.css文件内容:
#nav {float:left;}
ul {
list-style:none;
margin:0px;
padding:0px;
}
li{
margin:0px;
padding:0px;
width:100px;
height: 20px;
border:1px solid #ddd;
position: relative;
}
li ul{
background-color:#eee;
display:none;
top:0px;
left:100px;
position:absolute;
}
li:hover,li.hover {background-color:#eee;}
li:hover,li.hover ul{
display:block;
}