常用JS代码

一、获取cookie:

获取函数:

function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

调用:

getCookie("username");

 

二、获取UUID:

获取函数:

function generateUUID() {
    var d = new Date().getTime();
    if(window.performance && typeof window.performance.now === "function"){
        d += performance.now(); //use high-precision timer if available
    }
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = (d + Math.random()*16)%16 | 0;
        d = Math.floor(d/16);
        return (c=='x' ? r : (r&0x3|0x8)).toString(16);
    });
    return uuid;
}

调用:

generateUUID();

 

三、计时器:

var num = 60;
var timer = setInterval(function () {
    // 修改倒计时文本
    if (num > 1){
        // 修改倒计时文本
        $("xxx").html(num + '秒');
        num -= 1;
    } else {
        $("xxx").html('获取验证码');
        clearInterval(timer)
    }
}, 1000, 60)

 

posted @ 2020-08-13 12:31  组装梦想  阅读(173)  评论(0编辑  收藏  举报