// BOM // 判断是否为IE浏览器,返回-1或者版本号 function isIE() { var uUserAgent = navigator.userAgent; //保存浏览器的userAgent var ieAgent = uUserAgent.match(/msie (d+.d+)/i); if (ieAgent) { return ieAgent[1]; } else { if (uUserAgent.match(/Trident/7.0;/i)) { //处理到ie11. ieAgent = uUserAgent.match(/rv:(d+.d+)/i); return ieAgent[1]; } return -1; //不是ie浏览器。 } } /** * 设置cookie * @param {String} cookieName 设置cookie名 * @param {String} cookieValue 对对应的cookie名 * @param {Number} expiredays 过期的时间(多少天后) */ function setCookie(cookieName, cookieValue, expiredays) { var oDate = new Date(); oDate.setDate(oDate.getDate() + expiredays); document.cookie = cookieName + "=" + cookieValue + ";expires=" + oDate; } /** * 获取cookie * @param {String} cookieName 待寻找的cookie名 * @returns {String} 返回寻找到的cookie值,无时为空 */ function getCookie(cookieName) { var arr = document.cookie.split("; "); for (var i = 0; i < arr.length; i++) { var arr2 = arr[i].split("="); if (arr2[0] == cookieName) { return arr2[1]; } } return ""; } /** * 删除cookie * @param {String} cookieName 待删除的cookie名 */ function removeCookie(cookieName) { setCookie(cookieName, "1", -1) }