【发布时间】:2014-11-06 06:12:05
【问题描述】:
我试过了
function makeid()
{
var chars = "!~/-^";
var st = "It turns out tho, that if you append a string to the end of the URL that the CDN has never seen before, it will return the most recent version of the file. Bogus to be sure.";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
var output = makeid();
console.log(output);
使用上面的代码生成随机字符串现在我将如何将随机生成的字符串附加到给定字符串的随机位置。
谢谢
【问题讨论】:
-
追加表示在最后,你要在中间拼接吗?
-
@dandavis 我想将生成的随机字符串添加到给定字符串的不同位置。
标签: javascript jquery random