JavaScript 常用方法总结
1.手机类型判断
varBrowserInfo={userAgent:navigator.userAgent.toLowerCase()isAndroid:Boolean(navigator.userAgent.match(/android/ig)),isIphone:Boolean(navigator.userAgent.match(/iphone|ipod/ig)),isIpad:Boolean(navigator.userAgent.match(/ipad/ig)),isWeixin:Boolean(navigator.userAgent.match(/MicroMessenger/ig)),}
2.返回字符串长度,汉子计数为2
functionstrLength(str){vara=0;for(vari=0;i<str.length;i ){if(str.charCodeAt(i)>255)a =2;//按照预期计数增加2elsea ;}returna;}
3.获取url中的参数
functionGetQueryStringRegExp(name,url){varreg=newRegExp("(^|\?|