方法一(其实是毫秒时间数字字符串):
- function randomString() {
- return ‘‘ + new Date().getTime();
- }
方法二(随机字母数字字符串):
- var alpha_num_chars = ‘0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz‘.split(‘‘);
-
- function randomString(length) {
-
- if (! length) {
- length = Math.floor(Math.random() * alpha_num_chars.length);
- }
-
- var str = ‘‘;
- for (var i = 0; i < length; i++) {
- str += alpha_num_chars[Math.floor(Math.random() * alpha_num_chars.length)];
- }
- return str;
- }
-
- randomString();
-
- randomString(8);
使用Javascript实现随机字符串,布布扣,bubuko.com
使用Javascript实现随机字符串
原文:http://www.cnblogs.com/xiaochao12345/p/3905116.html