-3

此脚本应从可用字符中选择一个随机单词并将其添加到 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>
4

1 回答 1

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 参数做了什么。这符合您的需求吗?

于 2013-09-23T16:26:25.443 回答