zoukankan      html  css  js  c++  java
  • 常用JS代码

    一、根据cookie名称获取cookie的值

    // 函数定义
    function getCookie(name) {
        var r = document.cookie.match("\b" + name + "=([^;]*)\b");
        // 三步运算法
        // 对应python:return (r[1] if r else undefined)
        return r ? r[1] : undefined;
    }
    
    // 函数调用 var csrf_token = getCookie("csrf_token");

    二、生成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;
    }
    
    
    // 函数调用
    var uuid = generateUUID();

    三、文本周期变更(经典场景:点击按钮后的倒计时显示)

    var num = 60;
    
    var timer = setInterval(function () {
        // 修改倒计时文本
        if (num > 1){
            // 修改倒计时文本
            $(".phonecode-a").html(num + '秒');
    
            num -= 1;
        } else {
            $(".phonecode-a").html('获取验证码');
            $(".phonecode-a").attr("onclick", "sendSMSCode();");
            clearInterval(timer)
        }
    }, 1000, 60);
  • 相关阅读:
    用word2010发个blog
    停止调试无法关闭控制台
    D11.5.8,Lingo中不支持AS3的ExternalInterface接口
    Lingo03 通用脚本和自定义handler
    Lingo01 术语
    Lingo09 Sprite
    Lingo动态创建script member
    tut11脚本基础
    诡异失败的导入对话框
    Lingo3D01 3D Cast Member的组成
  • 原文地址:https://www.cnblogs.com/zzmx0/p/15225674.html
Copyright © 2011-2022 走看看