1.将URL参数返回,并转化为对象的方法:
1 function getUrlParams() { 2 var url = location.search; 3 var params = new Object(); 4 if (url.indexOf("?") != -1) { 5 var str = url.substr(1); 6 strs = str.split("&"); 7 for(var i = 0; i < strs.length; i ++) { 8 params[strs[i].split("=")[0]]=strs[i].split("=")[1]; 9 }10 }11 return params;12 };
2.将数值转换为1,0标志位
1 function splitToArray(number){ 2 var targets=[]; 3 var remainder; 4 var temp; 5 for(i=number,j=1;number>=j;i=i-((i/j)%2)*j,j=j*2){ 6 remainder=(i/j)%2; 7 if(remainder==1){ 8 targets=targets.concat(j); 9 }10 }11 return targets;12 }
3.将1,0标志位转换为数值
1 function caculateByArray(targets){2 var target=parseInt(0);3 for(i=0;i