javascript - 随机重定向到 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
非常感谢!!
解决方案
<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>
推荐阅读
- julia - 如何静音 JuMP(使用 cplex)日志进度?
- verilog - 数据写入多写端口 RAM 的同一地址
- sed - 如何从 dat 文件中保存特定的行
- php - 数据获取和 ahref 问题
- android - 如何强制 Margin-left (marginStart) 在片段中成像?
- java - 简单的 Docker 容器在 docker run 命令后立即死亡
- java - 如果派生类的定义不能被派生类覆盖/更改,为什么以及何时需要在派生类中重新声明静态方法?
- javascript - HTML中消失的按钮
- vb.net - 从 EWS 获取最新电子邮件
- android-studio - Android Studio 看不到单元测试