欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js遍歷、動態(tài)的添加數(shù)據(jù)的小例子

 更新時(shí)間:2013年06月22日 11:01:17   作者:  
js遍歷、動態(tài)的添加數(shù)據(jù)的小例子,需要的朋友可以參考一下
復(fù)制代碼 代碼如下:

function jsonObj(){
    var person= {name: 'zhangsan',pass: '123' ,'sni.ni' : 'XMQ',back:function (){
        for(var i=0;i<arguments.length;i++){
        //在不知參數(shù)個(gè)數(shù)情況下可通過for循環(huán)遍歷
        // arguments這個(gè)是js 默認(rèn)提供
        alert("arr["+i+"]="+arguments[i]);
        }
        }
        };
    //遍歷屬性
    for(var item in person){
        if(typeof person[item] === 'string'){
            alert("person中"+item+"的值="+person[item]);
            }else if(typeof person[item] === 'function'){
                person[item](1,1);
                //js 的function的參數(shù)可以動態(tài)的改變
                }
                }
    //添加屬性
    person.isMe = 'kaobian'; 
    // 這種是屬性名字正常的
    //當(dāng)屬性名字不正常時(shí),像下面這種,必須用這種形式的,
    person['isMe.kaobian'] = 'hello kaobian'; 
    //上面的也可以用下面的形式
    for(var item in person){
        if(typeof person[item] === 'string'){
            alert("person中"+item+"的值="+person[item]);
            }else if(typeof person[item] === 'function'){
                person[item](1,1);
                }
                }

}

相關(guān)文章

最新評論