javascript - 我想创建一个可以有多个列表项的水平导航栏
问题描述
我想创建一个包含多个列表项的导航栏。将主视图上的按钮数限制为 6 个按钮,其余页面放置在“...”菜单下。
我能够创建水平条,我想知道如何将其限制为 6 个按钮并将剩余的放置在“...”下
我正在从数据库中获取数据,并在 for 循环内部创建导航面板中的按钮。但是我想将其限制为 6 个按钮,其他项目应放在“...”下。当我们从“...”中选择一个项目时,它应该出现在屏幕上。如果我得到任何示例代码也会有所帮助。
下面是代码,不知道对调试有没有帮助。
for (var j = 0; j < memberNavigationList.$values.length; j++) {
var jitem = memberNavigationList.$values[j];
var url = integra_tolower(integra_trim(APPPATH + jitem.URL));
var currenturl = integra_tolower(integra_trim(self.location.href));
if ((jitem.URL.toLowerCase().indexOf('emr/summary/visitdock') != -1 || jitem.URL.toLowerCase() == 'applications/encounternote.aspx') && jitem.PreviousVisit != '' && jitem.PreviousVisit.length > 10) {
sidebar_nav.push('<li id="menuTertairyItemId_' + j + '" style="margin: 0 5px 0 0;" onmouseover="$ic.tertiaryNav.Showtooltip(this);" onclick="openVisitFromNavbar(\'')
sidebar_nav.push(jitem.PreviousVisit + '$' + jitem.PreviousVisitDate + '$' + EMRContextApplicationId);
if (jitem.URL.toLowerCase().indexOf('emr/summary/visitdock') != -1) {
sidebar_nav.push('\'' + ',' + '\'' + jitem.URL);
}
sidebar_nav.push('\');"');
sidebar_nav.push('data-toggle="tooltip" data-placement="bottom" title="' + jitem.Description + '" class="myTip btn pull-left ic2-flowsheet-btn-gray ' + ' ');
} else {
if (jitem.Indented === true) {
sidebar_nav.push('<li id="menuTertairyItemId_' + j + '" style="margin: 0 5px 0 0;" onclick="$ic.tertiaryNav.menuItemClicked(this,\'' + url + '\',\'' + jitem.URL.toUpperCase() + '\',\'' + jitem.description + '\',\'' + jitem.PageType + '\');" onmouseover="$ic.tertiaryNav.Showtooltip(this)" data-toggle="tooltip" data-placement="bottom" title="' + jitem.Description + '" class="myTip ic2-flowsheet-btn-gray btn pull-left ' + '');
} else {
sidebar_nav.push('<li id="menuTertairyItemId_' + j + '" style="margin: 0 5px 0 0;" onclick="$ic.tertiaryNav.menuItemClicked(this,\'' + url + '\',\'' + jitem.URL.toUpperCase() + '\',\'' + jitem.description + '\',\'' + jitem.PageType + '\');" onmouseover="$ic.tertiaryNav.Showtooltip(this)" data-toggle="tooltip" data-placement="bottom" title="' + jitem.Description + '" class="myTip ic2-flowsheet-btn-gray btn pull-left ' + '');
}
}
if (currenturl.indexOf(url) > -1 || (currenturl.match(/addpatientencounter.aspx/g) && url.match(/patientencounters.aspx/g))) {
sidebar_nav.push(' ic2-flowsheet-btn-gray-active ');
} else {
if (url.indexOf("popover") > -1) {
sidebar_nav.push(' ic2-flowsheet-btn-green ');
} else {
sidebar_nav.push(' ');
}
}
sidebar_nav.push('">');
sidebar_nav.push('<a href="#"></a>'+jitem.Description);
sidebar_nav.push('</li>');
}
}
sidebar_nav.push('</ul>'); // close the sidebarnav
解决方案
这是一个例子,它将帮助你......
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
.navbar {
overflow: hidden;
background-color: #333;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>
<div class="navbar">
<a href="#home">Home</a>
<a href="#news">News</a>
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</div>
<h3>Dropdown Menu inside a Navigation Bar</h3>
<p>Hover over the "Dropdown" link to see the dropdown menu.</p>
</body>
</html>
推荐阅读
- vue.js - 如何使用 Cloud Native Buildpacks 构建服务 Vue SPA 的容器
- powershell - PowerShell - 为什么在这行代码中使用数组?
- c - K&R 第 8.7 节 for free() 中的循环
- flutter - Flutter:默认值的好做法是什么(关于 shared_preferences)
- c# - 是否可以在文件中保存/存储数组中的对象?
- r - 如何在 R 中编写简单的循环来更新 URL 中的数字?
- java - Java“tasklist.exe /fo csv /nh”命令在等待过程中永远加载
- javascript - 如何在 Adobe 的扩展 JavaScript 文件中包含另一个文件
- javascript - React - 如何跟踪 useRef 孩子的变化
- flutter - 颤振在类和构造函数中为无状态小部件转换文本字段代码