js 常用代码
//获取url中的参数
function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 } function GetUrlParas(paras) { var url = location.href; var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&"); var paraObj = {}; for (var i = 0; j = paraString[i]; i++) { paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length); } var returnValue = paraObj[paras.toLowerCase()]; if (typeof (returnValue) == "undefined") { return ""; } else { return returnValue; } }
$.getUrlParam = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
//检查特殊字符
function CheckKeyCharacters(strString) {
var flag = true;
if (strString.length > 0) {
if (strString.indexOf('<') > -1) {
alert("检索文字中包含”<“");
flag = false;
} else if (strString.indexOf('&') > -1) {
alert("检索文字中包含”&“");
flag = false;
}
}
return flag;
}
//获取浏览器名字
function getBrowserInfo() { var userAgent = navigator.userAgent, rMsie = /(msie\s|trident.*rv:)([\w.]+)/; rChrome = /(chrome)\/([\w.]+)/; var regStr_ff = /(firefox)\/[\d.]+/gi var ua = userAgent.toLowerCase(); var win = "";//操作系统位数 if (ua.indexOf("win64") >= 0 || ua.indexOf("wow64") >= 0) { win = "x64"; } else if (ua.indexOf("win32") >= 0 || ua.indexOf("wow32") >= 0) { win = "x32"; } var win_vision = "other"; if (ua.indexOf("Windows NT 5.0") > -1 || ua.indexOf("Windows 2000") > -1) { win_vision = "windows2000"; } else if (ua.indexOf("Windows NT 5.1") > -1 || ua.indexOf("Windows XP") > -1) { win_vision = "xp"; } else if (ua.indexOf("Windows NT 5.2") > -1 || ua.indexOf("Windows 2003") > -1) { win_vision = "windows2003"; } else if (ua.indexOf("Windows NT 6.0") > -1 || ua.indexOf("Windows Vista") > -1) { win_vision = "vista"; } else if (ua.indexOf("Windows NT 6.1") > -1 || ua.indexOf("Windows 7") > -1) { win_vision = "win7"; } //alert(ua); if (rMsie.exec(ua) != null) { var match = rMsie.exec(ua); if ((ua.indexOf('aoyou') > -1) || (ua.indexOf('theworld') > -1) || (ua.indexOf('worldchrome') > -1) || (ua.indexOf('greenbrowser') > -1) || (ua.indexOf('baidu') > -1) || (ua.indexOf('qqbrowser') > -1) || ua.indexOf('maxthon') > -1 || ua.indexOf('chihiro') > -1 || ua.indexOf('7star') > -1 || ua.indexOf('airview') > -1) { return { browser: "", version: "0" }; } else if ((ua.indexOf('360ee') > -1) || (ua.indexOf('360se') > -1) || (ua.indexOf('se') > -1)) { return { browser: "360", version: "0", sys: win } } else { return { browser: "IE", version: match[2] || "0", sys: win, win_vision: win_vision }; } } else if (rChrome.exec(ua) != null) { var isChrome = window.clientInformation && window.clientInformation.permissions; if (isChrome) { var match = rChrome.exec(ua); return { browser: match[1] || "", version: match[2] || "0", sys: win, win_vision: win_vision }; } else if (ua.indexOf("maxthon") > -1) { return { browser: "aoyou", version: "0", sys: win, win_vision: win_vision }; } else if (ua.indexOf("edge") > -1) { return { browser: "edge", version: "0", sys: win, win_vision: win_vision }; } else { return { browser: "", version: "0", sys: win, win_vision: win_vision }; } } else if (ua.indexOf("firefox") > 0) { var match = regStr_ff.exec(ua); return { browser: match[1], version: "0", sys: win, win_vision: win_vision }; } else { return { browser: "", version: "0", sys: win, win_vision: win_vision }; } }
检查字符串 包含
if (url.indexOf("http://") === -1) { } else{ }