gpt4 book ai didi

javascript - Bootstrap 导航栏 : Is there a way to disable a few menu items even the parent for certain pages?

转载 作者:行者123 更新时间:2023-11-30 16:42:16 25 4
gpt4 key购买 nike

有没有办法禁用某些页面的某些菜单项和/或它的父项,但我对所有页面使用单个 navbar.jsp 并且它由每个页面上的 javascript 加载。

NavBar.jsp

<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="home.html" class="navbar-brand">SYSTRIX</a>
</div>

<div class="navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">My Console<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="home.html">Home</a></li>
<li><a href="users.html">User Management</a></li>
<li><a href="patients.html">Patient Management</a></li>
</ul>
</li>

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">New<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="userProfile.html">User</a></li>
<li><a href="patientsProfile.html">Patient</a></li>
<li><a href="#">Admission</a></li>
</ul>
</li>

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Edit<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">User Roles</a></li>
<li><a href="#">Patient Episode</a></li>
<li><a href="#">Patient Staff Assignment</a></li>
</ul>
</li>

<li><a href="#">Help</a></li>

<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</ul>
</div>
</div>
</nav>
</body>

脚本:

<script> 
$(function(){
$("#includedContent").load("navbar.jsp");
});
</script>

我需要为某些 .jsp 页面禁用某些菜单项 如果我在添加新页面上,编辑应该不可用。感谢您的帮助。

最佳答案

我认为这对你有用:

您应该将您的代码部分更改为:

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Edit<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#" id="userroles">User Roles</a></li>
<li><a href="#" id="patientepisode">Patient Episode</a></li>
<li><a href="#" id="patientstaff">Patient Staff Assignment</a></li>
</ul>
</li>

并使用这个 jquery 代码:

$(document).ready(function(){
var url = window.location.pathname;
var filename = url.substring(url.lastIndexOf('/')+1);

if(filename == 'Roles.jsp'){
$('#patientepisode').addClass('disabled');
$('#patientstaff').addClass('disabled');
}else if(filename == 'PatientEpisode.jsp'){
$('#userroles').addClass('disabled');
$('#patientstaff').addClass('disabled');
}else if(filename == 'StaffAssignment.jsp'){
$('#userroles').addClass('disabled');
$('#patientepisode').addClass('disabled');
}
});

希望对您有所帮助。

关于javascript - Bootstrap 导航栏 : Is there a way to disable a few menu items even the parent for certain pages?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31773469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com