点击右键和按钮进行显示隐藏div

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>Document</title>
    <style type="text/css">
    *{cursor: pointer;}
        #nav
        {
            width: 200px;
            height: 500px;
            background-color: red;
            border: 1px solid red;
        }
        #nav2
        {
            height: 30px;
        }
        #nav3
        {
            height: 30px;
        }
        body{
            width: 100%;
            height: 100%;

        }
    </style>
     <script type="text/javascript" src="jquery-1.12.4.min.js" ></script>
    <script type="text/javascript">
        
        window.onclick = function () {

              var ua =navigator.userAgent.toLowerCase();
                if(/(iPhone|iPad|iPod|iOS)/i.test(ua)){
                    alert("winua");
                    if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone-w"); }
                    else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad-w"); }
                    else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod-w"); }
                    else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS-w"); }

                }
                //要隐藏的 div 外点击事件
              //  alert("点击div外侧");
                if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                    // alert(navigator.userAgent);    
                    // window.location.href ="iPhone.html";
                 //   alert("iPhone|iPad|iPod|iOS");
                    if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone-w"); }
                    else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad-w"); }
                    else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod-w"); }
                    else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS-w"); }



                } else if (/(Android)/i.test(navigator.userAgent)) {
                    // alert(navigator.userAgent);   
                    // window.location.href ="Android.html";  
                    alert("Android-w");
                } else {
                    // alert(navigator.userAgent);  
                    alert("pc-w");
                    //  window.location.href ="pc.html";  
                };

                var ev = window.event || ev;
                hide('false', ev, 'nav');
            }

$(function($) {
         $(document).delegate("body", "click", function(e) {
    alert(1);
    bodyfu();
});
  });
     function bodyfu() {
            var ua = navigator.userAgent.toLowerCase();
            if (/(iPhone|iPad|iPod|iOS)/i.test(ua)) {
               alert(navigator.userAgent);   
                if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone-body"); }
                else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad-body"); }
                else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod-body"); }
                else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS-body"); }

            }else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                    // alert(navigator.userAgent);    
                    // window.location.href ="iPhone.html";
                    alert("iPhone|iPad|iPod|iOS");
                    if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone-body"); }
                    else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad-body"); }
                    else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod-body"); }
                    else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS-body"); }



                } else if (/(Android)/i.test(navigator.userAgent)) {
                    // alert(navigator.userAgent);   
                    // window.location.href ="Android.html";  
                    alert("Android.html-body");
                } else {
                    // alert(navigator.userAgent);  
                    alert("pc.html-body");
                    //  window.location.href ="pc.html";  
                };

            var ev = window.event || ev;
            hide('false', ev, 'nav');
        }
        document.onclick = function (ev) {
            var ua = navigator.userAgent.toLowerCase();
            if (/(iPhone|iPad|iPod|iOS)/i.test(ua)) {
               alert(navigator.userAgent);   
                if (/(iPhone)/i.test(navigator.userAgent)) { alert("docua-iPhone"); }
                else if (/(iPad)/i.test(navigator.userAgent)) { alert("docua-iPad"); }
                else if (/(iPod)/i.test(navigator.userAgent)) { alert("docua-iPod"); }
                else if (/(iOS)/i.test(navigator.userAgent)) { alert("docua-iOS"); }

            }else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                    // alert(navigator.userAgent);    
                    // window.location.href ="iPhone.html";
                    alert("iPhone|iPad|iPod|iOS");
                    if (/(iPhone)/i.test(navigator.userAgent)) { alert("iPhone"); }
                    else if (/(iPad)/i.test(navigator.userAgent)) { alert("iPad"); }
                    else if (/(iPod)/i.test(navigator.userAgent)) { alert("iPod"); }
                    else if (/(iOS)/i.test(navigator.userAgent)) { alert("iOS"); }



                } else if (/(Android)/i.test(navigator.userAgent)) {
                    // alert(navigator.userAgent);   
                    // window.location.href ="Android.html";  
                    alert("Android.html");
                } else {
                    // alert(navigator.userAgent);  
                    alert("pc.html");
                    //  window.location.href ="pc.html";  
                };

            var ev = window.event || ev;
            hide('false', ev, 'nav');
        }
        function hide(CheckShow, evt, id) {


            var obj = document.getElementById(id);
            var target = evt.target ? evt.target : evt.srcElement;
            if (CheckShow == "true") {
                //首先排除事件的
                obj.style.display = "block";
                return;
            } else
                if (target.id == "nav2" || target.id == "nav3" || target.id == "anani")
                    return;
                else
                    obj.style.display = "none";
        }
        function Show() {
            hide('true', 0, 'nav');
        }
        function hiden() {
            document.getElementById("nav").style.display = "none";

        }
    </script>
</head>
<body>
    <div id="nav">
    </div>
    <div id="nav2" οnclick="Show();">
        show</div>
    <div id="nav3" οnclick="hiden();">
        hiden</div>
</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值