生成时间戳随机数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title></title>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
        var No = 0;
        var key = new Date().getTime();//生成时间戳
        console.log("生成key", key);
        setCookie(key);//设置时间戳cookie


        function setCookie(c_name, value, expiredays) {
            var exdate = new Date()
            exdate.setDate(exdate.getDate() + expiredays)
            document.cookie = c_name + "=" + escape(value) +
            ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
        }

        function getCookie(c_name) {
            if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(c_name + "=")
                if (c_start != -1) {
                    c_start = c_start + c_name.length + 1
                    c_end = document.cookie.indexOf(";", c_start)
                    if (c_end == -1) c_end = document.cookie.length
                    return unescape(document.cookie.substring(c_start, c_end))
                }
            }
            return ""
        }
    </script>
</head>
<body>
    <span id="num"></span>
</body>
</html>

 

posted @ 2019-06-30 08:38  大da脸  阅读(4285)  评论(0编辑  收藏  举报