展开全部
var tokens = 'QWERTYUIOPASDFGHJKLZXCVBNM1234567890';
function randomStr (length) {
var str = '';
for(var i = 0; i< length; i++) {
var point = Math.round(Math.random() * (tokens.length - 1))
str += tokens [point];
}
return str;
}
var str = randomStr (6)
追问
请问可以再详细点不,body里面的内容
追答
<html>
<head>
<title>生成随机字符串</title>
<script>
var tokens = 'QWERTYUIOPASDFGHJKLZXCVBNM1234567890';
function randomStr (length) {
var str = '';
for(var i = 0; i< length; i++) {
var point = Math.round(Math.random() * (tokens.length - 1))
str += tokens [point];
}
return str;
}
</script>
</head>
<body>
<input id="show" type="text">
<input id="btn" type="button" value="生成随机字符串" onclick="show.value = randomStr(6)">
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询