Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在移动浏览器中显示/隐藏DIV_Jquery_Mobile_Browser Detection - Fatal编程技术网

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
a
div
。我目前的代码如下:

<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出现了。非常感谢。