开发者

How do I generate a number after a button is clicked? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Dupl开发者_如何学JAVAicate:

How to create a GUID / UUID in Javascript?

I need to have a script that generates random numbers and letters with a form that looks like this:

M3KRT-CKKYV-YH4G4-YXP42-46FMT

Prefer jQuery, or javascript. I know how to generate number when the button is click using the .click() method in jQuery. But I can not find out how to actually make the code :(


Like this: Create GUID / UUID in JavaScript?


Why do you include Win7 license key in your question?


Modified this example a little:

Create GUID / UUID in JavaScript?

And came up with this:

function S5() {
    return (((1 + Math.random()) * 0x100000) | 0).toString(16).substring(1);
}
function guid() {
    return (S5() + "-" + S5() + "-" + S5() + "-" + S5() + "-" + S5()).toUpperCase();
}


Try this out...

function createGuid () {
  for (var i=5, out=[]; i--;) {
    out.push((Math.random()*58786559+1679615|0).toString(36));
  }
  return out.join('-').toUpperCase();
}

alert(createGuid());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜