我正在尝试通过将变量动态传递给 URL 来动态地将部分添加到 URL,例如下面的代码。我怎样才能让下面的代码工作,以便 URL 看起来像这样:
http://www.test.com/test/Test_1/ato.50/[atc1.100/atc2.200/atc3.RandomNumber/atc3.RandomNumber/atc3.RandomNumber/atc4.400
其中 RandomNumber 是使用随机生成的数字Math.floor(Math.random() * 10 * 10());
(重复将数字传递给 atc3. 是有意的。)
代码:
<html>
<body>
<script>
var orderID = 50;
var Red = 100;
var Blue = 200;
var Green = [Math.floor(Math.random() * 10 * 10), Math.floor(Math.random() * 10 * 10), Math.floor(Math.random() * 10 * 10)];
var Yellow = 400;
var tag = '<s'+'cript language="JavaScript" src="http://www.test.com/test/Test_1/ato.' + orderID + '/[atc1.' + Red + '/atc2.' + Blue + '/atc3.' + Green[0];
i = 1;
while (i < Green.length){
var tag_two[i] ='/atc3.' + Green[i];
}
var tag_three ='/atc4.' + Yellow + ']"></s'+'cript>';
document.write(tag);
for (i = 0, i < Green.length, i++){
document.write(tag_two[i]);
}
document.write(tag_three);
</script>
</body>
</html>
谢谢!