getUrlArgObject(){ var me=this; var args=new Object(); var query=location.search.substring(1);//獲取查詢串 var pairs=query.split(",");//在逗號處斷開 for(var i=0;i<pairs.length;i++){ var pos=pairs[i].indexOf('=');//查找name=value if(pos==-1){//若是沒有找到就跳過 continue; } var argname=pairs[i].substring(0,pos);//提取name var value=pairs[i].substring(pos+1);//提取value args[argname]=unescape(value);//存爲屬性 } me.canshuList=Object.keys(args);//args獲取到的參數對象,若是隻想獲取到參數對象可掠過下面代碼。 if( me.canshuList.length==0){//判斷參數對象是否爲空 } },
Object.keys 數組
返回一個全部元素爲字符串的數組dom
案例:this
// simple array var arr = ['a', 'b', 'c']; console.log(Object.keys(arr)); // console: ['0', '1', '2'] // array like object var obj = { 0: 'a', 1: 'b', 2: 'c' }; console.log(Object.keys(obj)); // console: ['0', '1', '2'] // array like object with random key ordering var anObj = { 100: 'a', 2: 'b', 7: 'c' }; console.log(Object.keys(anObj)); // console: ['2', '7', '100'] // getFoo is a property which isn't enumerable var myObj = Object.create({}, { getFoo: { value: function () { return this.foo; } } }); myObj.foo = 1; console.log(Object.keys(myObj)); // console: ['foo']