请教,用jquery的递归函数如何自动生成树形菜单,我写了一点点jquery 后面不会写了 菜鸟求救

hulatumi 发布于 2012/04/19 11:21
阅读 4K+
收藏 0
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
li{list-style:none}
</style>

<script type="text/javascript">
$(document).ready(function(){
 menulist = {
             "menulist": [
                 { "MID": "1","PID":"0", "MName": "首页"},
                 { "MID": "2","PID":"0", "MName": "车辆生意"},
                 { "MID": "3","PID":"2", "MName": "新车"},
                 { "MID": "6","PID":"3", "MName": "奥迪"},
                 { "MID": "7","PID":"3", "MName": "别克"},
                 { "MID": "4","PID":"2", "MName": "二手车"},
                 { "MID": "5","PID":"2", "MName": "改装车"},
                 { "MID": "8","PID":"0", "MName": " 宠物"}
            ]
         };

 $(function (){
              $("#btn_bianli").click(function() {
                  var showlist = $("<ul></ul>");
      show(0,showlist,"|");
                 //showall(menulist.menulist, showlist);
                 $("#div_menu").append(showlist);
             });
         });
  
   function show(pid,showlist,str){
    str=str+"--";
    var menulist = $("<li></li>");
    for(pid > menulist){
    $(showlist).append(str+menulist){
      if(menulist(mid) == zi )
        show(mid,showlist,str)
      }
     }
    }

 })


</script>

</head>

<body>
<input type="button" id="btn_bianli"  value="button"/>
<div id="div_menu"></div> 
</body>
</html>
加载中
0
h
huxiaoqi

http://huxiaoqi.blog.51cto.com/3103971/845538  我的博客里有些 带checkbox的,不知道满足要求不

0
倪闯
倪闯
可以试试jquery.treeview.js插件
0
r
roywang

之前用了一个简陋的树插件,写过根据子节点递归展开父节点

一步步写,主要是把流程搞懂

返回顶部
顶部