js生成邀请码
Posted Ipeter
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js生成邀请码相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> <script> function uuid() { var s = []; var hexDigits = "0123456789abcdefghijklmnopq"; for (var i = 0; i < 6; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); } var uuid = s.join(""); document.getElementById("ic").value=uuid; } function MathRand() { var Num=""; for(var i=0;i<6;i++) { Num+=Math.floor(Math.random()*10); } document.getElementById("ic").value=Num; } function createInviteCode() { var randomChar = Math.random().toString(16).substr(9); document.getElementById("ic").value=randomChar; } </script> <body> <div> <input id="ic" type="text"/> <input id="yqmYqm" class="yqm" type="button" value="生成邀请码1" onclick="MathRand()"/> <input id="yqmYqm" class="yqm" type="button" value="生成邀请码2" onclick="uuid()"/> <input id="yqmYqm" class="yqm" type="button" value="生成邀请码3" onclick="createInviteCode()"/> </div> </body> </html>
以上是关于js生成邀请码的主要内容,如果未能解决你的问题,请参考以下文章