图像不是随机排列的?

时间:2018-01-31 19:47:56

标签: javascript html

function doSingle()
{
    var luck= ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
    var imagesArray = ["thumbs/lr/lrgokublack.png", "thumbs/lr/lrtrunks.png", "thumbs/lr/lrgohan.png", "thumbs/lr/lrmajinvegeta.png"];
    var ssrArray = ["thumbs/ssr/beerus1.png", "thumbs/ssr/broly1.png"];
    lucknumber = Math.floor((Math.random() * luck.length));

    if (lucknumber < 8) {
        function displayImage() {
        var num = Math.floor(Math.random() * ssrArray.length);
        window.canvas.src = ssrArray[num];
}
    } else {
        function displayImage() {
        var num = Math.floor(Math.random() * imagesArray.length);
        window.canvas.src = imagesArray[num];
        }
}
}

此代码不起作用,但我认为这是正确的?我很确定我的html代码中也调用了doSingle;

<head>
<p id="soup"></p>
<link rel="stylesheet" type="text/css" href="formalign.css">
      <script type="text/javascript" src="trinit5.js"></script>
      <input onclick="doSingle();" id="image" type="image" alt="Summon" src="ssbutton1.png" width="25%"/> 
      <img id="canvas"></img>
      <div class="element"></div>

</head>

我的意图是随意运气,依靠运气,一定数量会给你 SR SSR (稀有)另外,一些人说这个HTML代码是错误的,但它适用于我,并且当我更改它时将无法工作,所以我会保留原样:D提前谢谢!

编辑:在inspect元素中,是说doSingle()没有定义????

1 个答案:

答案 0 :(得分:1)

您有两个问题:

您已在内联声明变量,因此您不需要多次使用关键字r = -17.2788 -14.1372 -10.9956 -7.8540 -4.7124 0 0 4.7124 7.8540 10.9956 14.1372 17.2788

var

您没有调用函数var luck= ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], var imagesArray = ["thumbs/lr/lrgokublack. ^ ,您刚刚声明了它。所以,称之为。

displayImage

此代码段包含以下修复:

&#13;
&#13;
function displayImage() {
^
&#13;
function doSingle() {
  var luck = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
    imagesArray = ["thumbs/lr/lrgokublack.png", "thumbs/lr/lrtrunks.png", "thumbs/lr/lrgohan.png", "thumbs/lr/lrmajinvegeta.png"];
  var ssrArray = ["thumbs/ssr/beerus1.png", "thumbs/ssr/broly1.png"];
  lucknumber = Math.floor((Math.random() * luck.length));

  if (lucknumber < 8) {
    function displayImage() {
      var num = Math.floor(Math.random() * ssrArray.length);
      window.canvas.src = ssrArray[num];
    }

    displayImage();
  } else {
    function displayImage() {
      var num = Math.floor(Math.random() * imagesArray.length);
      window.canvas.src = imagesArray[num];
    };

    displayImage();
  }
}

doSingle();
&#13;
&#13;
&#13;