<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <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>标签:arr,p1,示例,text,BootStrap,var,TreeView,data,id From: https://www.cnblogs.com/joe-tang/p/7144796.html