js生成UUID

// 生成32位Id
    function generateUUID() {
      var str = 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'
      var timestamp = new Date().getTime()
      var uuid = str.replace(/[xy]/g, function (c) {
        var r = (Math.random() * 16) | 0
        var v = c == 'x' ? r : (r & 0x3) | 0x8
        return v.toString(16)
      })
      uuid = uuid.replace('y', ((timestamp & 0x3) | 0x8).toString(16))
      return uuid
    }

你可能感兴趣的:(javascript,java,html)