本文主要為大家詳細介紹了BootStrap TreeView使用實例,具有一定的參考價值,有興趣的小夥伴們可以參考一下,希望能幫助大家。
【相關影片推薦:Bootstrap教學】
<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> <p id="tree"></p> <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) --> <p class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <p class="modal-dialog"> <p class="modal-content"> <p class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button> <h4 class="modal-title" id="myModalLabel"> 模态框(Modal)标题 </h4> </p> <p class="modal-body"> <p id="tree"></p> </p> <p class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭 </button> <button type="button" class="btn btn-primary" id="btn"> 提交更改 </button> </p> </p><!-- /.modal-content --> </p><!-- /.modal --> </p> <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>
相關推薦:
jQuery TreeView樹形控制項之資料支援json字串、list集合
#以上是實例詳解BootStrap TreeView使用方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!