web手机端H5开发常用的js方法

//返回给定长度的随机字符串

function rans(a) {

            var b, c, d;
            if (localStorage.getItem("rans")) return localStorage.getItem("rans");
            for (a = a || 32, b = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678", c = b.length, d = "", i = 0; a > i; i++) d += b.charAt(Math.floor(Math.random() * c));
            return localStorage.setItem("rans", d),
                d

}

//获取cookie

function  getCookie(a) {
            var b = document.cookie,
                c = b.indexOf("" + a + "=");
            return - 1 == c && (c = b.indexOf(a + "=")),
                -1 == c ? b = null: (c = b.indexOf("=", c) + 1, cookieEndAt = b.indexOf(";", c), -1 == cookieEndAt && (cookieEndAt = b.length), b = unescape(b.substring(c, cookieEndAt))),
                b

 }

//保存cookie  默认保存到根 ‘/’下

function writeCookie(a, b, c) {
            var d = "";
            null != c && (d = new Date((new Date).getTime() + 36e5 * c), d = "; expires=" + d.toGMTString()),
                document.cookie = a + "=" + escape(b) + d + ";path=/"

}

//判断是否是微信

function isWeiXin() {
            var a = window.navigator.userAgent.toLowerCase();
            return "micromessenger" == a.match(/MicroMessenger/i) ? !0 : !1

}

//获取url参数

function getParams(a) {
            function c() {
                var a, b, f, c = /\+/g,
                    d = /([^&=]+)=?([^&]*)/g,
                    e = function(a) {
                        return decodeURIComponent(a.replace(c, " "))
                    };
                for (f = window.location.hash.substring() ? window.location.hash.substring().split("?")[1] : window.location.search.substring(1), a = {}; b = d.exec(f);) a[e(b[1])] = e(b[2]);
                return a
            }
            var b = c();
            return b[a]

}

//判断手机是否是IphoneX

function isIphoneX() {
            return navigator.userAgent.indexOf("iPhone") > -1 && 812 == screen.height && 375 == screen.width
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

isevena、

谢谢您的肯定

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值