首页 > Web开发 > 详细

JS 生成GUID 方法

时间:2016-05-09 17:01:40      阅读:212      评论:0      收藏:0      [点我收藏+]
var Guid={NewGuid: function () {
                var guid = (this._G() + this._G() +"-"+ this._G() +"-"+ this._G() +"-"+ this._G() +"-"+ this._G() + this._G() + this._G()).toUpperCase();
                return guid;
            },
            _G: function () {
                return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
            }
 };
console.log(Guid.NewGuid());
console.log(Guid.NewGuid());
console.log(Guid.NewGuid());
console.log(Guid.NewGuid());
// rfc4122 version 4
‘xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx‘.replace(/[xy]/g, function(c) {
    var r = Math.random()*16|0, v = c == ‘x‘ ? r : (r&0x3|0x8);
    return v.toString(16);
});

 

JS 生成GUID 方法

原文:http://www.cnblogs.com/sunshq/p/5474563.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!