Jquery 在移动浏览器中显示/隐藏DIV
如果浏览器是移动的,请查看Jquery 在移动浏览器中显示/隐藏DIV,jquery,mobile,browser-detection,Jquery,Mobile,Browser Detection,如果浏览器是移动的,请查看show/hideadiv。我目前的代码如下: <script> if(! navigator.userAgent.match(/Android/i) && ! navigator.userAgent.match(/webOS/i) && ! navigator.userAgent.match(/iPhone/i) && ! navigator.userAgent.match(/iPod/i) &
show/hide
adiv
。我目前的代码如下:
<script>
if(! navigator.userAgent.match(/Android/i) && ! navigator.userAgent.match(/webOS/i) && ! navigator.userAgent.match(/iPhone/i) && ! navigator.userAgent.match(/iPod/i) &&
! navigator.userAgent.match(/iPad/i) &&! navigator.userAgent.match(/Blackberry/i) )
{
$('#mobile').hide();
} else {
$('#mobile').show();
alert('tablet detected');
//turns on mobile DIV
}
</script>
如果(!navigator.userAgent.match(/Android/i)和&!navigator.userAgent.match(/webOS/i)和&!navigator.userAgent.match(/iPhone/i)和&!navigator.userAgent.match(/iPod/i)&&
!navigator.userAgent.match(/iPad/i)和&!navigator.userAgent.match(/Blackberry/i))
{
$('#mobile').hide();
}否则{
$('#mobile').show();
警报(“检测到平板电脑”);
//打开移动DIV
}
我在查看手机时收到
警报
,但没有看到我的#手机
分区。非常感谢您的建议。您的分区代码是什么?你确定你将“移动”定义为id而不是类吗?这个答案可能会有帮助:它可能会显示,但你只是看不到,因为你使用的是绝对定位,请尝试使用top:10px给它指定位置;左:例如10px
。只是想检查一下。啊,这是因为我试图在文档没有准备好的情况下执行脚本。我把脚本移到了我的文档底部,果然我的div出现了。非常感谢。