JS常用函数(不定期更新)
//js 判断是否在手机端 function inMobile() { var sUserAgent= navigator.userAgent.toLowerCase(); var bIsIpad= sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp= sUserAgent.match(/midp/i) == "midp"; var bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc= sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid= sUserAgent.match(/android/i) == "android"; var bIsCE= sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile"; if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) { return true; } return false; } /** * [是否是正确的手机号] * @param {[type]} mobile [description] * @return {Boolean} [description] */ function isMobile(mobile){ var reg = /^1[3-9]{1}[0-9]{9}$/; if( !reg.test(mobile) ) return false; return true; } /** * [字符串是否为空] * @param {[type]} str [description] * @return {Boolean} [description] */ function isEmpty(str){ var reg = /^\s+$/; if( reg.test(str) || str === '') return true; return false; } function showMsg(msg){ if( typeof(layer) !== 'object'){ alert('Layer手机端插件未定义'); return; } layer.open({ content: msg, skin: 'msg', time: 1 //1秒后自动关闭 }); }
Dcr163的博客
http://dcr163.cn/246.html(转载时请注明本文出处及文章链接)