这个脚本应该从可用字符中选择一个随机单词并添加它添加url的结尾但它似乎不起作用。你能确定我在哪里解决问题吗?
<script type="text/javascript">
function randomEI1(len) {
var chars = [ "apple", "google", "ebay" ];
var string_length = len;
var randomstring ='';
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
return randomstring;
}
var ei1 = randomEI1(1);
document.write('<script type="text/javascript" src="http://www.site.com' + ei1 + '"><\/script>');
</script>
答案 0 :(得分:0)
function randomEI1() {
var chars = [ "apple", "google", "ebay" ];
return chars[ Math.floor(Math.random() * chars.length)];
}
var ei1 = randomEI1();
document.write('<script type="text/javascript" src="http://www.site.com' + ei1 + '"> <\/script>');
我不确定你用len参数做了什么。这是否符合您的需求?