URL OR PC/PHONE OR Strlen

截取带有参数的URL

 

function GetRequest() {
var url = "?ie=utf-8&wd=化妆师有前途吗";
var theRequest = new Object();
var url_index = url.indexOf("?");
var strs;
if (url.indexOf("?") != -1){
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
}
}
console.log(theRequest.ie);
}

 

判断是手机还是电脑
var system ={};
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.x11){
 // 电脑
}else{
//手机
}

字符串长度

function strlen(o,str){
var len = 0;
for (var i=0; i<str.length; i++) {
var c = str.charCodeAt(i);
//单字节加1
if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
len++;
}
else {

//汉字加2
len+=2;
}
}

console.log(len);

}

posted @ 2016-04-06 14:48  刘~燕  阅读(110)  评论(0编辑  收藏  举报