JS判断PC显示div1;;手机显示div2,,,这样的JS代码该怎么写呢,请教大神啊???
2个回答
展开全部
给出真正能用的
参考引用地址“http://www.cnblogs.com/babycool/p/3583114.html”
<script type="text/javascript">
function browserRedirect() {
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) {
$(".leftslide").css("display","none");
$(".rightslide").css("display","block");
}
}
</script>
<div class="leftslide" style="display:block"></div>
<div class="rightslide" style="display:none">></div>
展开全部
使用navigator.userAgent判断
更多追问追答
追问
但求全部代码,谢谢,
追答
var nu = navigator.userAgent;
nu = nu.toLocaleLowerCase();
if(nu.indexOf('win') !== -1) {
console.log('opration system is win');
} else if(nu.indexOf('iphone') !== -1) {
console.log('iphone');
} else if(nu.indexOf('android')!== -1) {
console.log('android');
}
.....
还需要啥你自己加
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询