3
回答
请教,用jquery的递归函数如何自动生成树形菜单,我写了一点点jquery 后面不会写了 菜鸟求救
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   
<!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>
举报
hulatumi
发帖于6年前 3回/4K+阅
顶部