本文轉自:https://blog.csdn.net/s31415926_004/article/details/84256587css
其實這篇文章是給本身看的,之後忘記怎麼作回來還能看一下哈哈哈哈哈哈哈哈。。。嗝html
點擊左側菜單欄只刷新局部,局部就用iframe。jquery
首先先建layout頁,建左側菜單欄,而後下面的@RenderBody()ide
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll">
<!-- 左側導航區域(可配合layui已有的垂直導航) -->
<ul class="layui-nav layui-nav-tree" lay-filter="test">
<li class="layui-nav-item layui-nav-itemed Card">
<a class="" href="#">名片審覈</a>
</li>
<li class="layui-nav-item Project">
<a href="#">項目審覈</a>
</li>
<li class="layui-nav-item Funds"><a href="#">需求審覈</a></li>
</ul>
</div>
</div>
<div class="layui-body">
@RenderBody()
@RenderSection("scripts", required: false)
</div>
而後在最後寫上js用於點擊跳轉,上面的@RenderSection("scripts", required: false)和下面的#demoAdmin都在另外一個頁面中,也就是放iframe的頁面ui
<script>
//JavaScript代碼區域
layui.use('element', function () {
var $ = layui.jquery
, element = layui.element;
});
$(".Card").click(function () {
$("#demoAdmin").attr("src", "/Admin/CardManagement")
});
$(".Project").click(function () {
$("#demoAdmin").attr("src", "/Admin/ProjectManagement")
});
$(".Funds").click(function () {
$("#demoAdmin").attr("src", "/Admin/FundsManagement")
});
</script>
新建HomeController,新建Index頁面.net
@{
Layout = null;
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<iframe src="/Admin/CardManagement" frameborder="0" id="demoAdmin" style="width: 100%; height: 100%;"></iframe>
@section scripts{
<script>
reHeight();
$(window).resize(function () {
reHeight();
});
//設置iframe高度
function reHeight() {
var bodyHeight = $(window).height();
bodyHeight = bodyHeight - 107;
if (bodyHeight<400) {
bodyHeight = 400;
}
$("#demoAdmin").height(bodyHeight);
}
</script>
引用一下上面的layout。htm
其餘頁面引用Layout = "~/Areas/Admin/Views/Shared/_LayoutPage.cshtml";blog
我把css和js引用都放在了另外一個layout裏,因此我須要引用一下,不然頁面會亂。
---------------------
做者:PiNosan
來源:CSDN
原文:https://blog.csdn.net/s31415926_004/article/details/84256587
版權聲明:本文爲博主原創文章,轉載請附上博文連接!ip