Bootstrap 树形列表与右键菜单

介绍两个Bootstrap的扩展

  1. Bootstrap Tree View 树形列表
  2. jQuery contextMenu 右键菜单

Demo采用CDN分发,直接复制到本地就可以看到效果。也可以自己到上面的链接下载对应的js和css。

1. bootstrap-treeview

先上效果图:

不多BB,直接上完整Demo代码,复制下来自己对照着看,其他细节以及更多用法可以去上面的链接看作者怎么说。

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 兼容IE -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>bootstrap-treeview</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/2.7.1/jquery.contextMenu.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4">
<h2>默认</h2>
<div id="treeview1" class="">
</div>
</div>
<div class="col-sm-4">
<h2>自定义图标</h2>
<div id="treeview2" class="">
</div>
</div>
<div class="col-sm-4">
<h2>丰富多彩</h2>
<div id="treeview3" class="">
</div>
</div>
</div>
</div>
<!-- Script -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js"></script>
<script type="text/javascript">
$(function() { // 设置树的相关属性并构造树
$('#treeview1').treeview({
backColor: "#FFFFFF",
color: "#428bca",
enableLinks: true,
data: getTree()
});
$('#treeview2').treeview({
color: "#428bca",
expandIcon: 'glyphicon glyphicon-chevron-right',
collapseIcon: 'glyphicon glyphicon-chevron-down',
nodeIcon: 'glyphicon glyphicon-bookmark',
data: getTree()
});
$('#treeview3').treeview({
expandIcon: "glyphicon glyphicon-stop",
collapseIcon: "glyphicon glyphicon-unchecked",
nodeIcon: "glyphicon glyphicon-user",
color: "yellow",
backColor: "purple",
onhoverColor: "orange",
borderColor: "red",
showBorder: false,
showTags: true,
highlightSelected: true,
selectedColor: "yellow",
selectedBackColor: "darkorange",
data: getTree()
}); //定义树里的数据来源
function getTree(){
var data = [
{
text: 'Parent 1',
href: '#parent1',
tags: ['4'],
nodes: [
{
text: 'Child 1',
href: '#child1',
tags: ['2'],
nodes: [
{
text: 'Grandchild 1',
href: '#grandchild1',
tags: ['0']
},
{
text: 'Grandchild 2',
href: '#grandchild2',
tags: ['0']
}
]
},
{
text: 'Child 2',
href: '#child2',
tags: ['0']
}
]
},
{
text: 'Parent 2',
href: '#parent2',
tags: ['0']
},
{
text: 'Parent 3',
href: '#parent3',
tags: ['0']
},
{
text: 'Parent 4',
href: '#parent4',
tags: ['0']
},
{
text: 'Parent 5',
href: '#parent5' ,
tags: ['0']
}
];
return data;
}
});
</script>
</body>
</html>

jQuery-contextMenu

先上效果图:

完整Demo代码,复制下来自己对照着看,其他细节以及更多用法可以去上面的链接看作者怎么说。

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery-contextmenu</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/2.7.1/jquery.contextMenu.min.css">
</head>
<body>
<ul id="the-node" class="btn-group-vertical">
<li class="btn btn-primary">right click me 1</li>
<li class="btn btn-primary">right click me 2</li>
<li class="btn btn-primary">right click me 3</li>
<li class="btn btn-primary">right click me 4</li>
</ul> <!-- Script -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/2.7.1/jquery.contextMenu.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-contextmenu/2.7.1/jquery.ui.position.js"></script>
<script>
$(function(){
//注册右键菜单的项与动作
$('#the-node').contextMenu({
selector: 'li', // 选择器,为某一类元素绑定右键菜单
callback: function(key, options) {
var m = "clicked: " + key + " on " + $(this).text();
window.console && console.log(m) || alert(m);
},
items: {
"edit": {name: "Edit", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"copy": {name: "Copy", icon: "copy"},
"paste": {name: "Paste", icon: "paste"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: function($element, key, item){ return 'context-menu-icon context-menu-icon-quit'; }}
}
});
});
</script>
</body>
</html>

最新文章

  1. python之简单POST模拟登录
  2. 使用NodeJS、GruntCLI遇到的问题
  3. 技术英文单词贴--R
  4. 迅美VPS安装和配置MySQL数据库教程
  5. Knockout 新版应用开发教程之Observable Arrays
  6. bzoj2584
  7. C#中 Thread.Sleep精度问题
  8. Nexus搭建私服 学习
  9. JS中的 map, filter, some, every, forEach, for...in, for...of 用法总结
  10. Win10下, TortoiseGit安装及配合Gitee使用完整版
  11. Windows下return,exit和ExitProcess的区别和分析
  12. 四则运算-ppt演示
  13. hive添加UDF
  14. Android属性动画简单剖析
  15. gulp: Did you forget to signal async completion? 解决方案
  16. Django 2.0 学习(15):Web框架
  17. HDU 6183 Color it
  18. Microsoft Office Visio 2013 (安装 + 激活)
  19. [BZOJ1491][NOI2007]社交网络 floyd
  20. [ CodeVS冲杯之路 ] P1576

热门文章

  1. jdk,jre.jvm三者的关系
  2. Redis面试连环问,快看看你能走到哪一步
  3. LockSupport中的park()与unpark()
  4. csps2019AFO祭
  5. csp-s模拟测试59(10.4)「Reverse」(set)&#183;「Silhouette」(容斥)
  6. conn / as sysdba连接不上
  7. Redis并发竞争key的解决方案详解
  8. 97、配置yum源仓库服务器
  9. AcWing 243. 一个简单的整数问题2
  10. AcWing 201. 可见的点