判断设备及学习定义方法中的返回值使用
2016-07-07 14:56
393 查看
学习写法
1)定义判断设备的方法,注意返回值的使用
2)方法使用,先运行,取到返回值,方便下面直接使用
3)使用 userAgent.type 使用返回值
1)定义判断设备的方法,注意返回值的使用
function getUserAgent() { var userAgent = navigator.userAgent, iPhone = userAgent.indexOf('iPhone') > -1, iPad = userAgent.indexOf('iPad') > -1, iPod = userAgent.indexOf('iPod') > -1, Android = userAgent.indexOf('Android') > -1; if (iPhone || iPad || iPod) { return { type: 'iOS' }; } else if (Android) { return { type: 'Android' }; } else { return { type: '' }; } }
2)方法使用,先运行,取到返回值,方便下面直接使用
var userAgent = getUserAgent();
3)使用 userAgent.type 使用返回值
if(userAgent.type == 'iOS'){ alert('苹果设备'); }else{ alert('安卓及其他设备'); }
相关文章推荐
- lintcode: 左填充
- 聊聊分布式事务
- 基于CoreText的基础排版引擎
- android developer tiny share-20160704
- android developer tiny share-20160704
- 《机器学习实战》之决策树
- Java的常见异常
- RS232、RS485、TTL电平、CMOS电平区别
- Linux 下的 Redis 安装 && 启动 && 关闭 && 卸载
- poj 2001 Shortest Prefixes 字典树
- MySQL查看相关信息
- Jmeter使用过程记录---安装(一)
- Android中ViewPager + Fragment使用ButterKnife注解时出现空指针NullPoint的情况
- asp.net core 中文乱码
- 深入浅出ES6(十四):let和const
- 获得日期中的月份
- 深入浅出ES6(十四):let和const
- Poj 2001 Shortest Prefixes
- centos安装lamp环境
- iOS开发:NSURLSession和Afnetworking的使用对比