标签归档:uuid

【转】javascript生成UUID的方法

javascript生成UUID的方法,

原文来自How to create a GUID / UUID in Javascript?

//generate uuid by javascript
function s4() {
  return Math.floor((1 + Math.random()) * 0x10000)
             .toString(16)
             .substring(1);
};

function guid() {
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
         s4() + '-' + s4() + s4() + s4();
}

//use this method
var uuid =  guid();