标签:style c class blog code java
JS 中的{}表示一个对象。[]表示数组。
$.each()
each处理数组或json对象。
1 var arr1 = [ "aaa", "bbb", "ccc" ]; 2 $.each(arr1, function(i,val){ 3 alert(i); 4 alert(val); 5 });
制作菜单:
1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: Administrator 5 * Date: 14-5-27 6 * Time: 上午10:19 7 */ 8 header("Content-Type:text/html;charset=utf-8"); 9 ?> 10 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> 11 <script> 12 //理解json对象 13 var arr=[1,3,4,5,6,7,"7"];//相当于 arr=Array(1,3,4,5,6,7,"7"); 14 document.write(arr[2]); 15 16 var ss={‘name‘:"小明",‘age‘:18}; 17 document.write("我的名字是"+ss[‘name‘]+" 我"+ss.age+"了<br/>"); 18 19 var my=function(){ 20 return "123456"; 21 }; 22 document.write(my()+"<br/>"); 23 var person={ 24 name:function(){return "abama"}, 25 age:function(){return "52"} 26 }; 27 document.write(person.name()+person.age()); 28 29 //menus 是一个菜单包含多个模块。如何读取出并显示它 30 var _menus={‘meuns‘:[ 31 { 32 ‘meunid‘:1,‘meunname‘:"系统管理", 33 ‘meuns‘:[{‘name‘:‘添加用户‘,‘icon‘:‘‘,‘url‘:‘http://www.baidu.com‘}, 34 {‘name‘:‘删除用户‘,‘icon‘:‘‘,‘url‘:‘‘}, 35 {‘name‘:‘修改权限‘,‘icon‘:‘‘,‘url‘:‘‘}, 36 {‘name‘:‘系统日志‘,‘icon‘:‘‘,‘url‘:‘‘} 37 ]}, 38 { 39 ‘meunid‘:2,‘meunname‘:"财务管理", 40 ‘meuns‘:[{‘name‘:‘财务付款‘,‘icon‘:‘‘,‘url‘:‘http://www.baidu.com‘}, 41 {‘name‘:‘财务审核‘,‘icon‘:‘‘,‘url‘:‘‘}, 42 {‘name‘:‘查看‘,‘icon‘:‘‘,‘url‘:‘‘}, 43 {‘name‘:‘没了‘,‘icon‘:‘‘,‘url‘:‘‘} 44 ]} 45 ]}; 46 document.write(_menus.meuns[1].menus[0].name); 47 48 </script> 49 50 <script> 51 function Set_Meuns(){ 52 $(‘#meuns‘).empty(); 53 var list=""; 54 $.each(_menus.meuns,function(i,k){ 55 list+="<div title=‘"+ k.meunname+"‘><ul>" 56 $.each(k.meuns,function(i,k){ 57 list+="<li><a href=‘"+ k.url+"‘>" + k.name+"</a></li>"; 58 }); 59 list+="</ul></div>"; 60 }); 61 62 63 alert(list); 64 $(‘#meuns‘).append(list); 65 } 66 $(document).ready(function(){ 67 Set_Meuns(); 68 }) 69 </script> 70 71 <html> 72 <body> 73 <div id="meuns" style="border:1 solid red;width:300px;"> 74 菜单列表位置 75 </div> 76 77 </body> 78 </html>
标签:style c class blog code java
原文地址:http://www.cnblogs.com/canbefree/p/3755261.html