// 移动设备侦测 var isMobile = { Android: function () { return navigator.userAgent.match(/Android/i); }, BlackBerry: function () { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function () { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function () { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function () { return navigator.userAgent.match(/IEMobile/i); }, any: function () { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } };
判断IE
isIE: function (num) { var name = navigator.appVersion.toUpperCase(); return num ? name.match(/MSIE (d)/) && name.match(/MSIE (d)/)[1] == num : /MSIE (d)/.test(name); }
创建弹窗
function showMsg(msgContent){ var box = document.createElement("div"); var msg = document.createElement("div"); box.setAttribute("id", "showMsgBox"); msg.setAttribute("id", "msgBox"); with(box.style){ position = "absolute"; top = 0; left = 0; bottom = 0; right = 0; background = "rgba(255,255,255,.6)"; } with(msg.style){ margin = "0 auto"; width = "500px"; height = "400px"; marginTop = "100px"; padding = "55px"; paddingBottom = "110px"; fontSize = "30px"; fontFamily = "微软雅黑"; lineHeight = "40px"; background = "#D1D1D1"; borderRadius = "12px"; } msg.innerHTML = msgContent || "空"; box.appendChild(msg); document.body.appendChild(box); } showMsg("内容")
按键
$("#textinput").keydown(function(e) { e.keyCode; // this value });