您的位置:首页 > 产品设计 > UI/UE

JS 生成GUID 方法

2016-05-09 16:55 423 查看
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);
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: