码迷,mamicode.com
首页 > 其他好文 > 详细

生成时间戳随机数

时间:2019-06-30 09:40:11      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:date()   lang   console   col   bst   ext   tar   get   function   

<!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>

 

生成时间戳随机数

标签:date()   lang   console   col   bst   ext   tar   get   function   

原文地址:https://www.cnblogs.com/romanticcrystal/p/11108601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!