javascript - 向 Weebly 添加随机页面按钮

标签 javascript html weebly

我已经尝试在我的 Weebly 网站上添加一个随机页面按钮很长一段时间了,以便我的用户可以单击它,并将他们带到随机游戏页面。我研究了这个主题并找到了一些指南,但它们似乎不起作用。这是我的代码。它永远不会起作用。

<script type="text/javascript">
function randomlinks(){
    var myrandom=Math.round(Math.random()*85)
    var links=new Array()
    links[0]="http://www.awesomeinternetgames.weebly.com/age-of-war"
    links[1]="http://www.awesomeinternetgames.weebly.com/age-of-war-2"
    links[2]="http://www.awesomeinternetgames.weebly.com/apple-shooter"
    links[3]="http://www.awesomeinternetgames.weebly.com/avalanche"
    links[4]="http://www.awesomeinternetgames.weebly.com/band-rpg"
    links[5]="http://www.awesomeinternetgames.weebly.com/bloons-td-5"
    links[6]="http://www.awesomeinternetgames.weebly.com/bloons-td-4"
    links[7]="http://awesomeinternetgames.weebly.com/canyon-defense"
    links[8]="http://awesomeinternetgames.weebly.com/cyclomaniacs"
    links[9]="http://awesomeinternetgames.weebly.com/cock-shooter"
    links[10]="http://awesomeinternetgames.weebly.com/corporate-soccer-2"
    links[11]="http://awesomeinternetgames.weebly.com/counter-terror"
    links[12]=”http://awesomeinternetgames.weebly.com/commando”
    links[13]=”http://awesomeinternetgames.weebly.com/commando-2”
    links[14]=”http://awesomeinternetgames.weebly.com/copter”
    links[15]=”http://awesomeinternetgames.weebly.com/corporation-inc”
    links[16]=”http://awesomeinternetgames.weebly.com/cubefield”
    links[17]=”http://awesomeinternetgames.weebly.com/curve-fever”
    links[18]=”http://awesomeinternetgames.weebly.com/demolition-city-2”
    links[19]=”http://awesomeinternetgames.weebly.com/dead-zed-2”
    links[20]=”http://awesomeinternetgames.weebly.com/dino-run”
    links[21]=”http://awesomeinternetgames.weebly.com/drag-racer”
    links[22]=”http://awesomeinternetgames.weebly.com/duck-life-4”
    links[23]=”http://awesomeinternetgames.weebly.com/dune-buggy”
    links[24]=”http://awesomeinternetgames.weebly.com/earn-to-die-2-exodus”
    links[25]=”http://awesomeinternetgames.weebly.com/earn-to-die”
    links[26]=”http://awesomeinternetgames.weebly.com/earn-to-die-2012”
    links[27]=”http://awesomeinternetgames.weebly.com/earn-to-die-2012-part-2”
    links[28]=”http://awesomeinternetgames.weebly.com/effing-worms”
    links[29]=”http://awesomeinternetgames.weebly.com/effing-worms-2”
    links[30]=”http://awesomeinternetgames.weebly.com/enough-plumbers”
    links[31]=”http://awesomeinternetgames.weebly.com/fireboy-and-watergirl”
    links[32]=”http://awesomeinternetgames.weebly.com/flappy-bird-flash”
    links[33]=”http://awesomeinternetgames.weebly.com/flight”
    links[34]=”http://awesomeinternetgames.weebly.com/game-corp”
    links[35]=”http://awesomeinternetgames.weebly.com/gravity-guy”
    links[36]=”http://awesomeinternetgames.weebly.com/happy-wheels”
    links[37]=”http://awesomeinternetgames.weebly.com/helic”
    links[38]=”http://awesomeinternetgames.weebly.com/infected”
    links[39]=”http://awesomeinternetgames.weebly.com/infectonator-2”
    links[40]=”http://awesomeinternetgames.weebly.com/innkeeper”
    links[41]=”http://awesomeinternetgames.weebly.com/into-space”
    links[42]=”http://awesomeinternetgames.weebly.com/into-space-2”
    links[43]=”http://awesomeinternetgames.weebly.com/kingdom-rush”
    links[44]=”http://awesomeinternetgames.weebly.com/the-last-stand”
    links[45]=”http://awesomeinternetgames.weebly.com/learn-to-fly”
    links[46]=”http://awesomeinternetgames.weebly.com/learn-to-fly-2”
    links[47]=”http://awesomeinternetgames.weebly.com/learn-to-fly-3”
    links[48]=”http://awesomeinternetgames.weebly.com/moby-dick-2”
    links[49]=”http://awesomeinternetgames.weebly.com/monster-trucks-nitro”
    links[50]=”http://awesomeinternetgames.weebly.com/papa-louie”
    links[51]=”http://awesomeinternetgames.weebly.com/planet-racer”
    links[52]=”http://awesomeinternetgames.weebly.com/pointer”
    links[53]=”http://awesomeinternetgames.weebly.com/potty-racers”
    links[54]=”http://awesomeinternetgames.weebly.com/porry-racers-2”
    links[55]=”http://awesomeinternetgames.weebly.com/portal-flash”
    links[56]=”http://awesomeinternetgames.weebly.com/escaping-the-prison”
    links[57]=”http://awesomeinternetgames.weebly.com/breaking-the-bank”
    links[58]=”http://awesomeinternetgames.weebly.com/stealing-the-diamond”
    links[59]=”http://awesomeinternetgames.weebly.com/renegade-racing”
    links[60]=”http://awesomeinternetgames.weebly.com/rollercoaster-creator”
    links[61]=”http://awesomeinternetgames.weebly.com/rogue-soul”
    links[62]=”http://awesomeinternetgames.weebly.com/rubble-trouble-moscow”
    links[63]=”http://awesomeinternetgames.weebly.com/rubble-trouble-new-york”
    links[64]=”http://awesomeinternetgames.weebly.com/run”
    links[65]=”http://awesomeinternetgames.weebly.com/rural-racer”
    links[66]=”http://awesomeinternetgames.weebly.com/shop-empire”
    links[67]=”http://awesomeinternetgames.weebly.com/shop-empire-2”
    links[68]=”http://awesomeinternetgames.weebly.com/shopping-city”
    links[69]=”http://awesomeinternetgames.weebly.com/shopping-street”
    links[70]=”http://awesomeinternetgames.weebly.com/snake”
    links[71]=”http://awesomeinternetgames.weebly.com/sniper-assassin”
    links[72]=”http://awesomeinternetgames.weebly.com/sugarsugar2”
    links[73]=”http://awesomeinternetgames.weebly.com/super-mario-flash”
    links[74]=”http://awesomeinternetgames.weebly.com/stick-war”
    links[75]=”http://awesomeinternetgames.weebly.com/strike-force-heroes”
    links[76]=”http://awesomeinternetgames.weebly.com/strike-force-heroes-2”
    links[77]=”http://awesomeinternetgames.weebly.com/stunt-pilot”
    links[78]=”http://awesomeinternetgames.weebly.com/tank-trouble”
    links[79]=”http://awesomeinternetgames.weebly.com/territory-war”
    links[80]=”http://awesomeinternetgames.weebly.com/theme-hotel”
    links[81]=”http://awesomeinternetgames.weebly.com/trials-2”
    links[82]=”http://awesomeinternetgames.weebly.com/tu-46”
    links[83]=”http://awesomeinternetgames.weebly.com/tu-95”
    links[84]=”http://awesomeinternetgames.weebly.com/the-unfair-platformer”
    links[85]=”http://awesomeinternetgames.weebly.com/valet-parking-3d”
    links[86]=”http://awesomeinternetgames.weebly.com/zombie-trailer-park”

    window.location=links[myrandom]
}
</script>
<form>
<input type="button" value="Click here for a random game!" onClick="randomlinks()">
</form>

仅供引用here是指向应用代码的测试页面的链接。

最佳答案

尝试使用以下代码...

<script type="text/javascript">
function randomlinks() {
    var links = [
      "http://www.awesomeinternetgames.weebly.com/age-of-war",
      "http://www.awesomeinternetgames.weebly.com/age-of-war-2",
      "http://www.awesomeinternetgames.weebly.com/apple-shooter",
      "http://www.awesomeinternetgames.weebly.com/avalanche",
      "http://www.awesomeinternetgames.weebly.com/band-rpg",
      "http://www.awesomeinternetgames.weebly.com/bloons-td-5",
      "http://www.awesomeinternetgames.weebly.com/bloons-td-4",
      "http://awesomeinternetgames.weebly.com/canyon-defense",
      "http://awesomeinternetgames.weebly.com/cyclomaniacs",
      "http://awesomeinternetgames.weebly.com/cock-shooter",
      "http://awesomeinternetgames.weebly.com/corporate-soccer-2",
      "http://awesomeinternetgames.weebly.com/counter-terror",
      "http://awesomeinternetgames.weebly.com/commando",
      "http://awesomeinternetgames.weebly.com/commando-2",
      "http://awesomeinternetgames.weebly.com/copter",
      "http://awesomeinternetgames.weebly.com/corporation-inc",
      "http://awesomeinternetgames.weebly.com/cubefield",
      "http://awesomeinternetgames.weebly.com/curve-fever",
      "http://awesomeinternetgames.weebly.com/demolition-city-2",
      "http://awesomeinternetgames.weebly.com/dead-zed-2",
      "http://awesomeinternetgames.weebly.com/dino-run",
      "http://awesomeinternetgames.weebly.com/drag-racer",
      "http://awesomeinternetgames.weebly.com/duck-life-4",
      "http://awesomeinternetgames.weebly.com/dune-buggy",
      "http://awesomeinternetgames.weebly.com/earn-to-die-2-exodus",
      "http://awesomeinternetgames.weebly.com/earn-to-die",
      "http://awesomeinternetgames.weebly.com/earn-to-die-2012",
      "http://awesomeinternetgames.weebly.com/earn-to-die-2012-part-2",
      "http://awesomeinternetgames.weebly.com/effing-worms",
      "http://awesomeinternetgames.weebly.com/effing-worms-2",
      "http://awesomeinternetgames.weebly.com/enough-plumbers",
      "http://awesomeinternetgames.weebly.com/fireboy-and-watergirl",
      "http://awesomeinternetgames.weebly.com/flappy-bird-flash",
      "http://awesomeinternetgames.weebly.com/flight",
      "http://awesomeinternetgames.weebly.com/game-corp",
      "http://awesomeinternetgames.weebly.com/gravity-guy",
      "http://awesomeinternetgames.weebly.com/happy-wheels",
      "http://awesomeinternetgames.weebly.com/helic",
      "http://awesomeinternetgames.weebly.com/infected",
      "http://awesomeinternetgames.weebly.com/infectonator-2",
      "http://awesomeinternetgames.weebly.com/innkeeper",
      "http://awesomeinternetgames.weebly.com/into-space",
      "http://awesomeinternetgames.weebly.com/into-space-2",
      "http://awesomeinternetgames.weebly.com/kingdom-rush",
      "http://awesomeinternetgames.weebly.com/the-last-stand",
      "http://awesomeinternetgames.weebly.com/learn-to-fly",
      "http://awesomeinternetgames.weebly.com/learn-to-fly-2",
      "http://awesomeinternetgames.weebly.com/learn-to-fly-3",
      "http://awesomeinternetgames.weebly.com/moby-dick-2",
      "http://awesomeinternetgames.weebly.com/monster-trucks-nitro",
      "http://awesomeinternetgames.weebly.com/papa-louie",
      "http://awesomeinternetgames.weebly.com/planet-racer",
      "http://awesomeinternetgames.weebly.com/pointer",
      "http://awesomeinternetgames.weebly.com/potty-racers",
      "http://awesomeinternetgames.weebly.com/porry-racers-2",
      "http://awesomeinternetgames.weebly.com/portal-flash",
      "http://awesomeinternetgames.weebly.com/escaping-the-prison",
      "http://awesomeinternetgames.weebly.com/breaking-the-bank",
      "http://awesomeinternetgames.weebly.com/stealing-the-diamond",
      "http://awesomeinternetgames.weebly.com/renegade-racing",
      "http://awesomeinternetgames.weebly.com/rollercoaster-creator",
      "http://awesomeinternetgames.weebly.com/rogue-soul",
      "http://awesomeinternetgames.weebly.com/rubble-trouble-moscow",
      "http://awesomeinternetgames.weebly.com/rubble-trouble-new-york",
      "http://awesomeinternetgames.weebly.com/run",
      "http://awesomeinternetgames.weebly.com/rural-racer",
      "http://awesomeinternetgames.weebly.com/shop-empire",
      "http://awesomeinternetgames.weebly.com/shop-empire-2",
      "http://awesomeinternetgames.weebly.com/shopping-city",
      "http://awesomeinternetgames.weebly.com/shopping-street",
      "http://awesomeinternetgames.weebly.com/snake",
      "http://awesomeinternetgames.weebly.com/sniper-assassin",
      "http://awesomeinternetgames.weebly.com/sugarsugar2",
      "http://awesomeinternetgames.weebly.com/super-mario-flash",
      "http://awesomeinternetgames.weebly.com/stick-war",
      "http://awesomeinternetgames.weebly.com/strike-force-heroes",
      "http://awesomeinternetgames.weebly.com/strike-force-heroes-2",
      "http://awesomeinternetgames.weebly.com/stunt-pilot",
      "http://awesomeinternetgames.weebly.com/tank-trouble",
      "http://awesomeinternetgames.weebly.com/territory-war",
      "http://awesomeinternetgames.weebly.com/theme-hotel",
      "http://awesomeinternetgames.weebly.com/trials-2",
      "http://awesomeinternetgames.weebly.com/tu-46",
      "http://awesomeinternetgames.weebly.com/tu-95",
      "http://awesomeinternetgames.weebly.com/the-unfair-platformer",
      "http://awesomeinternetgames.weebly.com/valet-parking-3d",
      "http://awesomeinternetgames.weebly.com/zombie-trailer-park"
    ];
    var myrandom = Math.floor(Math.random() * links.length);
    window.location = links[myrandom];
}
</script>
<form>
<input type="button" value="Click here for a random game!" onclick="randomlinks()">
</form>

关于javascript - 向 Weebly 添加随机页面按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43103187/

相关文章:

javascript - 在 Google Chart 中显示/隐藏线条/数据

javascript - 在 Weebly 中维护产品图像大小和纵横比

html - { 乌尔都语博客文章文本对齐(从右到左); }

css - 如何禁用我的产品图片的缩放效果?

javascript - d3js v5 + Topojson v3 关于加入 csv & json 的优化

javascript - 注册 5 秒后隐藏 div

html - Twitter Bootstrap 图片库未显示标题

html - 将 Bootstrap 导航栏内的图像垂直对齐到基线

javascript - 从回调函数内部将项目添加到全局数组,然后全局访问它

javascript - 排序json数组