87,839
社区成员




$("nav").on("click", ".menuP>a", function () { //一级菜单单击事件
$(this).next('ul').slideToggle();
}).on("click", ".menuC>a", function () { //二级菜单单击事件
//somecode
});
$(".menuP>a").on("click", function () { //一级菜单单击事件
$(this).next('ul').slideToggle();
});
$(".menuC>a").on("click", function () { //二级菜单单击事件
//somecode
});
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="main.aspx.cs" Inherits="main" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta charset="utf-8">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<title>纬尚尼POS系统</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js"></script>
<style type="text/css">
/*导航栏 导航栏 导航栏*/
nav {
position: absolute;
width: 9em;
margin: 0.2em;
border: 1px solid red;
overflow: auto;
}
.menuP a:link, .menuP a:visited {
display: block;
text-decoration: none;
color: blue;
padding: 0.25em;
}
.menuP a:hover, .menuP a:active {
background-color: gainsboro;
}
.menuP {
margin-left: 0.25em;
}
.menuC {
margin-left: 1em;
}
ul {
list-style-type: none;
}
ul span {
display: none;
}
</style>
<script>
$(document).ready(function () {
//获取菜单
$.post(
"UserManage/UserPost.aspx",
{
action: "getMenuJSON",
},
function (result) {
if (result == "-1") {
alert("会话已过期,请重新登录");
self.location = "Login.aspx";
}
if (result == "-2") {
alert("参数出错,请联系管理员");
return false;
}
var showList = $("<ul></ul>");
showAll(JSON.parse(result).MenuP, showList);
$("nav").append(showList); //将菜单添加到导航区
}
);
$(".menuP>a").on("click", function () { //一级菜单单击事件
$(this).next('ul').slideToggle();
});
$(".menuC>a").on("click", function () { //二级菜单单击事件
//检测是否存在,存在就显示,不存在则检测数量
var temti = -1;
for (var i = 1; i < $(".text").length; i++) {
if ($(".text").eq(i).text() == $(this).text()) {
temti = i;
break;
};
};
if (temti != -1) {
ti = temti;
showtabs();
} else {
testcount($(this).text(), $(this).prev().text());
};
});
//生成菜单列表
function showAll(menuJSON, parent) {
$.each(menuJSON, function (index, fatherLi) { //遍历数据集
var li = $("<li class='menuP'> <a href='#'>" + fatherLi.Pname + "</a></li>");
var ul = $("<ul><ul>");
$.each(fatherLi.MenuC, function (i, child) {
var lic = $("<li class='menuC'><span>" + child.Url + "</span><a href='#'>" + child.Cname + "</a></li>");
$(ul).append(lic);
})
$(li).append(ul);
$(parent).append(li);
});
};
</script>
</head>
<body>
<form id="form1" runat="server">
<nav>
</nav>
</form>
</body>
</html>