欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jQuery插件zTree实现更新根节点中第i个节点名称的方法示例

程序员文章站 2023-11-23 17:53:16
本文实例讲述了jquery插件ztree实现更新根节点中第i个节点名称的方法。分享给大家供大家参考,具体如下: 1、实现代码:

本文实例讲述了jquery插件ztree实现更新根节点中第i个节点名称的方法。分享给大家供大家参考,具体如下:

1、实现代码:

<!doctype html>
<html>
<head>
  <title>ztree实现基本树</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <link rel="stylesheet" type="text/css" href="ztree_v3/css/demo.css" rel="external nofollow" >
  <link rel="stylesheet" type="text/css" href="ztree_v3/css/ztreestyle/ztreestyle.css" rel="external nofollow" >
  <script type="text/javascript" src="ztree_v3/js/jquery-1.4.4.min.js"></script>
  <script type="text/javascript" src="ztree_v3/js/jquery.ztree.core.min.js"></script>
  <script type="text/javascript">
    <!--
    var setting = {
      data: {
        simpledata: {
          enable: true
        }
      }
    };
    var znodes =[
      { id:1, pid:0, name:"湖北省", open:true},
      { id:11, pid:1, name:"武汉市", open:true},
      { id:111, pid:11, name:"汉口"},
      { id:112, pid:11, name:"汉阳"},
      { id:113, pid:11, name:"武昌"},
      { id:12, pid:1, name:"黄石市"},
      { id:121, pid:12, name:"黄石港区"},
      { id:122, pid:12, name:"西塞山区"},
      { id:123, pid:12, name:"下陆区"},
      { id:124, pid:12, name:"铁山区"},
      { id:13, pid:1, name:"黄冈市"},
      { id:131, pid:13, name:"黄州区"},
      { id:132, pid:13, name:"麻城市"},
      { id:133, pid:13, name:"武穴市"},
      { id:134, pid:13, name:"团风县"},
      { id:135, pid:13, name:"浠水县"},
      { id:136, pid:13, name:"罗田县"},
      { id:137, pid:13, name:"英山县"},
      { id:2, pid:0, name:"湖南省", open:true},
      { id:21, pid:2, name:"长沙市", open:true},
      { id:211, pid:21, name:"芙蓉区"},
      { id:212, pid:21, name:"天心区"},
      { id:213, pid:21, name:"岳麓区"},
      { id:214, pid:21, name:"开福区"},
      { id:22, pid:2, name:"株洲市"},
      { id:221, pid:22, name:"天元区"},
      { id:222, pid:22, name:"荷塘区"},
      { id:223, pid:22, name:"芦淞区"},
      { id:224, pid:22, name:"石峰区"}
    ];
    $(document).ready(function(){
      $.fn.ztree.init($("#basetree"), setting, znodes);
    });
    /**
     * 更新根节点中第i个节点的名称
     */
    function updatenodes()
    {
      var treeobj = $.fn.ztree.getztreeobj("basetree");
      //获取节点
      var nodes = treeobj.getnodes();
      if (nodes.length>0)
      {
        for(var i=0;i<nodes.length;i++)
        {
          // 更新根节点中第i个节点的名称
          nodes[i].name = "省份名称";
          treeobj.updatenode(nodes[i]);
        }
      }
    }
    //-->
  </script>
 </head>
<body>
<div class="content_wrap">
  <div class="ztreedemobackground left">
    <ul id="basetree" class="ztree" style="height: 300px; width:200px; overflow-y: auto"></ul>
    <input type="button" id="btn" onclick="updatenodes()" value="更新根节点中第i个节点的名称"/>
  </div>
</div>
</body>
</html>

2、运行效果:

(1)初始化

jQuery插件zTree实现更新根节点中第i个节点名称的方法示例

(2)单击按钮后

jQuery插件zTree实现更新根节点中第i个节点名称的方法示例

3、设计说明

// 更新根节点中第i个节点的名称
nodes[i].name = "省份名称";
treeobj.updatenode(nodes[i]);

附:ztree_v3插件点击此处本站下载

更多关于jquery相关内容感兴趣的读者可查看本站专题:《jquery常用插件及用法总结》、《jquery中ajax用法总结》、《jquery表格(table)操作技巧汇总》、《jquery扩展技巧总结》、《jquery常见经典特效汇总》及《jquery选择器用法总结

希望本文所述对大家jquery程序设计有所帮助。