BootStrap TreeView使用实例详解
程序员文章站
2022-09-08 15:50:21
本文实例为大家分享了bootstrap treeview使用代码,供大家参考,具体内容如下
本文实例为大家分享了bootstrap treeview使用代码,供大家参考,具体内容如下
<html> <head> <title></title> <link href="/scripts/bootstrap/css/bootstrap.css" rel="stylesheet"> <link href="/scripts/bootstrap/css/bootstrap-treeview.css" rel="stylesheet"> <script src="/scripts/bootstrap/js/jquery.js" type="text/javascript"></script> <script src="/scripts/bootstrap/js/bootstrap-treeview.js" type="text/javascript"></script> </head> <body> <div id="tree"></div> <input type="button" id="btn" value="查询" /> <script type="text/javascript"> $(function () { function gettree() { // some logic to retrieve, or generate tree structure var data = [{ text: "p1", nodes: [{ text: "p1-1", id: '00001', nodeid: '00001' }, { text: "p1-2", id: '00002' }, { text: "p1-3", id: '00003' }, { text: "p1-4", id: '00004', nodes: [{ text: 'p1-1-1', id: '00005'}]}] }] return data; } var obj = {}; obj.text = "123"; $('#tree').treeview({ data: gettree(), // data is not optional levels: 5, multiselect: true }); $("#btn").click(function (e) { var arr = $('#tree').treeview('getselected'); alert(json.stringify(arr)); for (var key in arr) { alert(arr[key].id); } }) }) </script> </body> </html>
弹窗口+树形菜单的具体代码
<html> <head> <title></title> <link href="/scripts/bootstrap/css/bootstrap.css" rel="stylesheet"> <link href="/scripts/bootstrap/css/bootstrap-treeview.css" rel="stylesheet"> <script src="/scripts/bootstrap/js/jquery.js" type="text/javascript"></script> <script src="/scripts/bootstrap/js/bootstrap.js" type="text/javascript"></script> <script src="/scripts/bootstrap/js/bootstrap-treeview.js" type="text/javascript"></script> </head> <body> <p id="c"></p> <!-- 按钮触发模态框 --> <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#mymodal"> 开始演示模态框 </button> <!-- 模态框(modal) --> <div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button> <h4 class="modal-title" id="mymodallabel"> 模态框(modal)标题 </h4> </div> <div class="modal-body"> <div id="tree"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭 </button> <button type="button" class="btn btn-primary" id="btn"> 提交更改 </button> </div> </div><!-- /.modal-content --> </div><!-- /.modal --> </div> <script type="text/javascript"> $(function () { function gettree() { // some logic to retrieve, or generate tree structure var data = [{ text: "p1", nodes: [{ text: "p1-1", id: '00001', nodeid: '00001' }, { text: "p1-2", id: '00002' }, { text: "p1-3", id: '00003' }, { text: "p1-4", id: '00004', nodes: [{ text: 'p1-1-1', id: '00005'}]}] }] return data; } var obj = {}; obj.text = "123"; $('#tree').treeview({ data: gettree(), // data is not optional levels: 5, multiselect: true }); $("#btn").click(function (e) { var arr = $('#tree').treeview('getselected'); for (var key in arr) { c.innerhtml = c.innerhtml + "," + arr[key].id; } }) }) </script> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: 太监是个高危职业!晚上伺候嫔妃鞋子里竟然还要放东西?
下一篇: two.js之实现动画效果示例