---
title: "网页换肤程序(在水平下拉菜单和垂直下拉菜单之间切换)"
author: "qinxike"
date: "2009-07-04T14:33:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2012-02-10T10:36:35Z"
id: 1401651
url: "https://qinxike.iteye.com/blog/1401651"
---

网页换肤程序(在水平下拉菜单和垂直下拉菜单之间切换)

今天终于写完了一个 可以水平下拉菜单和垂直下拉菜单之间随意切换的网页换肤程序,它综合应用了水平下拉菜单,垂直下拉菜单,网页换肤等技巧.

这个程序需要用到三个文件,一个是h.css,用作水平下拉菜单的样式文件,另一个是v.css,用作垂直下拉菜单的样式文件,最后一个就是包含下拉菜单内容的网页文档test.html.

test.html文件内容:

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  
"[http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)"&gt;  
&lt;html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)" xml:lang="en" lang="en"&gt;  
&lt;head&gt;  
&lt;script&gt;  
function startlist()  
{

if(document.all)  
{

var navRoot = document.getElementById("nav");  
for(var i=0;i&lt;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");  
}  
&lt;/script&gt;

&lt;link rel="stylesheet" type="text/css" href="h.css" id="cssfile"/&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;ul id="nav"&gt;  
&lt;li&gt;java培训  
&lt;ul&gt;  
&lt;li&gt;java基础提高&lt;/li&gt;  
&lt;li&gt;java就业实战&lt;/li&gt;  
&lt;li&gt;java高手精华&lt;/li&gt;  
&lt;/ul&gt;  
&lt;/li&gt;  
&lt;li&gt;.net培训  
&lt;ul&gt;  
&lt;li&gt;.net基础提高&lt;/li&gt;  
&lt;li&gt;.net就业实战&lt;/li&gt;  
&lt;li&gt;.net高手精华&lt;/li&gt;  
&lt;/ul&gt;  
&lt;/li&gt;  
&lt;li&gt;&lt;a href="#" onclick="changeSkin()"&gt;切换样式&lt;/a&gt;&lt;/li&gt;  
&lt;/ul&gt;  
&lt;div id="content"&gt;  
内容区  
&lt;/div&gt;  
&lt;/body&gt;  
&lt;/html&gt;

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;  
}