首页 > 解决方案 > 随机重定向到 url 但 1 个数字更改(通过 Javascript)

问题描述

所以,我使用这段代码

<script type="text/javascript">

var urls = new Array();
urls[0] = "/truth";
urls[1] = "/truth1";
urls[2] = "truth2";

var random = Math.floor(Math.random()*urls.length);

window.location = urls[random];

</script>

我使用“/truth1”“/truth2”“dare1”等

是否有可能让javascript在我设置的URL末尾自动放置一个随机数?

换句话说,我希望Javascript在
truthordare0.weebly.com /truth
truthordare0.weebly.com /dare

的末尾添加一个数字到 truthordare0.weebly.com /dare1,truthordare0.weebly.com / dare2
到truthordare0.weebly.com /truth1,truthordare0.weebly.com /truth2
在“truth”或“dare”的末尾放置一个 1-25 之间的随机数。如果我必须将数字设为两位数,请告诉我!



知道可能很方便:
- 上面的代码将用于 truthordare0.weebly.com /truth
(将重定向到/truth1/truth2等 - 上面的代码用于 vitemulti.weebly.com/yesorno-select

非常感谢!!

标签: javascripthtmlurlredirectrandom

解决方案


<script type="text/javascript">

var urls = new Array();
urls[0] = "/truth";
urls[1] = "/truth1";
urls[2] = "truth2";

var random = Math.floor(Math.random()*urls.length);

window.location = "https://truthordare0.weebly.com/" + urls[random];

</script>


推荐阅读