代码改变世界

Js常用方法总结

2016-08-11 11:01  熠旸  阅读(204)  评论(0编辑  收藏  举报

/* 手机类型判断 */

<script>
$(function(){
var BrowserInfo = {
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)),
}
if (BrowserInfo.isAndroid == true)
{
alert("isAndroid");
}
else if (BrowserInfo.isIphone == true)
{
alert("isIphone");
}
else if (BrowserInfo.isIpad == true)
{
alert("isIpad");
}
else if (BrowserInfo.isWeixin == true) {
alert("Weixin");
}
else {
alert("can not find");
}
})

</script>