ASP版的 <
%
function
makePassword(maxLen)
'
方法一
Dim
strNewPass
Dim
whatsNext, upper, lower, intCounter
Randomize
For
intCounter
= 1 To
maxLen
whatsNext
= Int
((
3
)
* Rnd + 0
)
If
whatsNext
= 0 Then
'
生成大写字母
'
'character
upper
= 90
lower
= 65
Elseif
whatsNext
= 1 then
'
生在数字
upper
= 57
lower
= 48
else
'
生成小写字母
upper
=
122
lower
=
97
End If
strNewPass
=
strNewPass
& Chr
(
Int
((upper
-
lower
+ 1
)
* Rnd +
lower))
Next
makePassword
=
strNewPass
end function
Function
RoundStr( str,Num)
'
方法二
s
= ""
for
i
= 1 to
Num
Randomize
strLen
= Len
(str)
t
= Round
((
RND *
(strLen
-
1
))
+
1
)
s
=
s
& mid
(str,t,
1
)
Next
RoundStr
=
s
End Function
'
response.write makePassword(10)&"
"
tmp
= "
0123456789abcdefghijklmnopqrstopwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
"
'
response.writeRoundStr(tmp,10)&"
"
%
> JavaScript版的
<
script
>
function
makePassword(maxLen)
{
var
strNewPass
=
""
;
var
whatsNext, upper, lower, intCounter;
for
(intCounter
=
1
;
intCounter
<=
maxLen;
intCounter
++
)
{
whatsNext
=
Math.floor(
3
*
Math.random());
switch
(whatsNext)
{
case 0
:
//
生成大写字母
upper
=
90
;
lower
=
65
;
break
;
case 1
:
//
生成数字
upper
= 57
;
lower
= 48
;
break
;
case 2
:
//
生成小写字母
upper
= 122
;
lower
= 97
;
break
;
}
strNewPass
=
strNewPass
+
(String.fromCharCode(Math.floor((upper
-
lower
+ 1
)
*
Math.random()
+
lower)));
}
return
strNewPass
}
document.write(makePassword(
13
))
script
>
文章图片
<
INPUT
TYPE
="text"
NAME
="Password"
>
文章图片
<
INPUT
TYPE
="button"
value
="https://www.it610.com/article/随机生成密码"
onClick
="document.getElementById('Password').value=https://www.it610.com/article/(makePassword(13))"
>
推荐阅读
- 操作系统|[译]从内部了解现代浏览器(1)
- web网页模板|如此优秀的JS轮播图,写完老师都沉默了
- JavaScript|vue 基于axios封装request接口请求——request.js文件
- vue.js|vue中使用axios封装成request使用
- JavaScript|JavaScript: BOM对象 和 DOM 对象的增删改查
- JavaScript|JavaScript — 初识数组、数组字面量和方法、forEach、数组的遍历
- JavaScript|JavaScript — call()和apply()、Date对象、Math、包装类、字符串的方法
- JavaScript|JavaScript之DOM增删改查(重点)
- javascript|vue使用js-xlsx导出excel,可修改格子样式,例如背景颜色、字体大小、列宽等
- javascript|javascript中的数据类型转换