前端面试题(代码题)

来源:互联网 发布:淘宝店铺seo有哪些 编辑:程序博客网 时间:2024/06/05 23:48
            //描述:不使用零时变量,两个变量值互换                <script type="text/javascript">            var a=5,b=7;            b=b-a;            a=a+b;            b=a-b;            console.log(a);            console.log(b);                    </script>            //描述:||赋值        <script type="text/javascript">            var m,n,result;            result=((m=1)||(n=2));            console.log("m="+m);            console.log("n="+n);        </script>           //描述:水平垂直居中
  .box{                width: 100px;                height: 100px;                background: cyan;                margin: auto;                position: absolute;

            }

            //描述:判断终端        function IsPC() {            var userAgentInfo = navigator.userAgent;            alert(userAgentInfo);            var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");            var flag = true;            for(var v = 0; v < Agents.length; v++) {                if(userAgentInfo.indexOf(Agents[v]) > 0) {                    flag = false;                    break;                }            }            alert(flag);            return flag;        }        IsPC();

         //判断不同终端跳转         function pageskip(){             //text方法:RegExpObject.test(string)             //检测正则对象RegExpObject是否出现于字符串中,出现返回true,否则返回false             if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {                  window.location.href = "http://www.baidu.com";//移动端跳转页面            } else {                window.location.href = "https://wx.qq.com/";//pc端跳转页面            }         }        pageskip();  

          
0 0
原创粉丝点击