87,997
社区成员




///获取系统
const GetSystemType = function GetSystemType() {
var u = navigator.userAgent.toLowerCase()
var isAndroid =
u.indexOf('android') > -1 ||
u.indexOf('Android') > -1 ||
u.indexOf('Adr') > -1 //android终端
var isiOS =
u.indexOf('iphone') > 0 || u.indexOf('ipad') > 0 || u.indexOf('Mac OS') > 0
if (isAndroid) {
return 1
}
if (isiOS) {
return 2
} else {
return 3
}
}
这是封装的方法,返回1是安卓,返回2是ios,返回3是web
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<button class="pc" style="color:#666;border:0;background:#fff;font-size:15px;display: none;" type="button" onclick="dianwo()">我的PC电脑要显示的内容</button>
<a class="mobile" style="display: none;" href="http://www.baidu.com">我是移动设备要显示的内容</a>
</div>
<script>
function getAgentType() {
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
return 'mobile';
}
return 'pc';
}
function dianwo(){
console.log('dianwo')
}
window.onload = function(){
const eles = document.getElementsByClassName(getAgentType());
Array.from(eles).map(ele => ele.style.display = "block");
}
</script>
</body>
</html>