用户控件 分类列表导航栏
图片在另一篇博文中有上传:显示图片效果
1 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NavDevice.ascx.cs" Inherits="IOT.Web.NavDevice" %>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<style type="text/css">
body
{
margin: 0;
text-align: left;
color: #000;
font: normal 12px Arial,Verdana,Tahoma;
background: #C8D0D5;
line-height: 150%;
}
a:link, a:visited
{
color: #385065;
text-decoration: none;
font-size:12px;
}
a:hover
{
text-decoration: underline;
}
#menu
{
width: 150px;
margin: 0px 15px;
padding: 0px;
text-align: left;
list-style: none;
}
#menu .item
{
margin: 5px 0px;
padding: 0px;
list-style: none;
}
a.title:link, a.title:visited, a.title:hover
{
display: block;
color: #385065;
font-weight: bold;
padding: 2px 0 0 22px;
width: 128px;
line-height: 23px;
cursor: pointer;
text-decoration: none;
}
#menu .item ul
{
border: 0px solid #9FACB7;
margin: 0;
width: 118px;
padding: 3px 0px 3px 30px;
background: #fff;
list-style: none;
display: none;
}
#menu .item ul li
{
display: block;
</style>
1 <div>
2 <ul id="menu">
3 <li class="item"><a href="DeviceADLNA.aspx?oid=1" onclick="javascript:void(0)" class="title"
4 name="1">DLNA Device</a>
5 <ul id="opt_1" class="optiton">
6 <li><a href="DeviceADLNA.aspx?oid=1&cid=1">PHF</a></li>
7 <li><a href="DeviceADLNA.aspx?oid=1&cid=2">Charger& USB</a></li>
8 <li><a href="DeviceADLNA.aspx?oid=1&cid=3">BT Headset</a></li>
9 <li><a href="DeviceADLNA.aspx?oid=1&cid=4">NFC Tag</a></li>
10 </ul>
11 </li>
12 <li class="item"><a href="DeviceADLNA.aspx?oid=2" onclick="javascript:void(0)" class="title"
13 name="2">SE Device</a>
14 <ul id="opt_2" class="optiton">
15 <li><a href="#">PHF</a></li>
16 <li><a href="#">Charger& USB</a></li>
17 <li><a href="#">BT Headset</a></li>
18 <li><a href="#">NFC Tag</a></li>
19 </ul>
20 </li>
21 <li class="item"><a href="DeviceADLNA.aspx?oid=3" onclick="javascript:void(0)" class="title"
22 name="3">Non-SE Device</a>
23 <ul id="opt_3" class="optiton">
24 <li><a href="#">PHF</a></li>
25 <li><a href="#">Charger& USB</a></li>
26 <li><a href="#">BT Headset</a></li>
27 <li><a href="#">NFC Tag</a></li>
28 </ul>
29 </li>
30 </ul>
31 </div>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<script type="text/javascript">
// --- 获取ClassName
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var j = 0; j < elem.length; j++) {
var classes = elem[j].className;
if (myclass.test(classes)) retnode.push(elem[j]);
}
return retnode;
}
// --- 隐藏所有
function HideAll() {
var items = document.getElementsByClassName("optiton");
for (var j=0; j<items.length; j++) {
items[j].style.display = "none";
}
}
// --- 设置cookie
function setCookie(sName,sValue,expireHours) {
var cookieString = sName + "=" + escape(sValue);
//;判断是否设置过期时间
if (expireHours>0) {
var date = new Date();
date.setTime(date.getTime + expireHours * 3600 * 1000);
cookieString = cookieString + "; expire=" + date.toGMTString();
}
document.cookie = cookieString;
}
//--- 获取cookie
function getCookie(sName) {
var aCookie = document.cookie.split("; ");
for (var j=0; j < aCookie.length; j++){
var aCrumb = aCookie[j].split("=");
if (escape(sName) == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
window.onload = function() {
var show_item = "opt_1";
if (getCookie("show_item") != null) {
show_item= "opt_" + getCookie("show_item");
}
document.getElementById(show_item).style.display = "block";
var items = document.getElementsByClassName("title");
for (var j=0; j<items.length; j++) {
items[j].onclick = function() {
var o = document.getElementById("opt_" + this.name);
if (o.style.display != "block") {
HideAll();
o.style.display = "block";
setCookie("show_item",this.name);
}
else {
o.style.display = "none";
}
}
}
}
</script>
Be the change you want to see in the world.