随机字符串生成器 - WebCat
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>WebCat</title>
<script src="js/jquery.min.js"></script>
<script src="js/wc-3.0.6.min.js"></script>
</head>
<body>
<h1 id="title">Hello world</h1>
<p id="p1">点击生成随机字符串</p>
<script>
const options = ['1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
<pre><code> function generateRandomString() {
let selected = [];
while(selected.length < 12) {
let randomIndex = Math.floor(Math.random() * options.length);
let randomChar = options[randomIndex];
if(selected.indexOf(randomChar) === -1) {
selected.push(randomChar);
}
}
$('#title').text(selected.join('') );
}
p1.onclick = generateRandomString;
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/obwT 著作权归作者所有。请勿转载和采集!