成都創新互聯主營利津網站建設的網絡公司,主營網站建設方案,成都App制作,利津h5重慶小程序開發公司搭建,利津網站營銷推廣歡迎利津等地區企業咨詢
-----后臺
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } public string GetzNodes() { StringBuilder sb = new StringBuilder(); sb.Append("<script>"); sb.Append("var zNodes =["); //*****************************************加入遍歷代碼 for (int i = 0; i < 100; i++) { if (i > 50) { sb.Append(SetParametes(i.ToString(), "1", "b")); } else sb.Append(SetParametes(i.ToString(), "-1", "a")); } //******************************************************** sb.Append("];"); sb.Append("</script>"); return sb.ToString(); } /// <summary> /// 設置節點 /// </summary> /// <param name="id">id</param> /// <param name="pid">父級id</param> /// <param name="name">名稱</param> /// <param name="open">是否展開?</param> /// <returns>返回節點</returns> private string SetParametes(string id, string pid, string name,bool open=false) { StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.AppendFormat("id:{0},",id); sb.AppendFormat("pId:{0},",pid); if (open) { sb.AppendFormat("name:\"{0}\",", name); sb.Append("open: true"); } else { sb.AppendFormat("name:\"{0}\"", name); } sb.Append("},"); return sb.ToString(); } }
-----前臺
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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 runat="server"> <title></title> <link href="../css/demo_new.css" rel="stylesheet" type="text/css" /> <link href="../css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" /> <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script> <script src="../js/jquery.ztree.core-3.5.js" type="text/javascript"></script> </head> <%=GetzNodes()%> <script type="text/javascript"> var setting = { data: { simpleData: { enable: true} }, callback: { onClick: zTreeOnClick} }; $(document).ready(function () { $.fn.zTree.init($("#treeDemo"), setting, zNodes); }); //顯示div function showdiv() { $("#zhezhao").fadeIn(300); $("#treeDemodiv").fadeIn(300); } //隱藏div function closediv() { $("#zhezhao").fadeOut(300); $("#treeDemodiv").fadeOut(300); } //展示zTree function showZTree() { var w = document.documentElement.clientWidth; var h = document.documentElement.clientHeight; var l = document.documentElement.clientWidth / 2 - $("#treeDemodiv").width() / 2; var t = document.documentElement.clientHeight / 2 - $("#treeDemodiv").height() / 2; $("#zhezhao").css({ "width": w + "px", "height": h + "px", "filter": "alpha(opacity=25)", "-moz-opacity": "0.25", "-khtml-opacity": "0.25", "opacity": "0.25" }); $("#treeDemodiv").css({ "left": l + "px", "top": t + "px" }); showdiv(); } //點擊觸發事件 function zTreeOnClick(event, treeId, treeNode) { alert(treeNode.id + "," + treeNode.name); closediv(); } </script> <body> <form id="form1" runat="server"> <input type="button" value="顯示" onclick="showZTree()"> <!------------------Treediv---------------------> <div id="treeDemodiv" class="zTreeDemoBackground left"> <ul ><li ><img onclick="$('#treeDemodiv').fadeOut(300);$('#zhezhao').fadeOut(300);" src="../img/yzfalse.png" /></li></ul> <ul id="treeDemo" class="ztree"></ul> </div> <div id="zhezhao" ></div> <!------------------Treediv---------------------> </form> </body> </html>
整合包下載:http://down.51cto.com/data/1967063
文章標題:1,最簡單的樹--標準JSON數據
分享URL:http://vcdvsql.cn/article26/peiejg.html
成都網站建設公司_創新互聯,為您提供面包屑導航、移動網站建設、建站公司、外貿網站建設、企業建站、App開發
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯