【问题标题】:Random array with index带索引的随机数组
【发布时间】:2014-07-15 13:18:02
【问题描述】:

我有一个问题我可能因为筋疲力尽而无法解决。在我的页面中,我有两个框,其中按下“开始”按钮会随机更改背景颜色而无需重复。起初它有效,然后我改变了一些东西,它不再像以前那样有效。有时我不会使两个窗格上的颜色出现在数组中。这是我的代码

function go(){
    var random = Math.floor((Math.random() * colori.length) + 0);
    var t = Math.floor((Math.random() * colori.length) + 0);
         var sx = document.getElementById("sx");
       var dx = document.getElementById("dx");
       var btngo = document.getElementById("go");

        document.getElementById("scritta").innerHTML = random;
       document.getElementById("scrittaU").innerHTML = t;




       dx.style.backgroud = colori[random];
       sx.style.backgroud = colori[t];

       if(random == t){
       alert("random:"+random+" " +"t"+t);
       alert(colori.splice(random,1));
       random = Math.floor((Math.random() * colori.length) + 0);
       dx.style.background = colori[t];

    sx.style.background = colori[random];
       colori.splice(random,1);
       colori.splice(t,1);

       }

    dx.style.background = colori[t];

    sx.style.background = colori[random];

    colori.splice(random,1);
    colori.splice(random-1,1);

    btngo.disabled=true;
    }

【问题讨论】:

  • 只说没用的时候很难帮你
  • 基本上我将照片随机化,但有时在两个面板中留下两个相同

标签: javascript html if-statement random colors


【解决方案1】:
 dx.style.backgroud = colori[random];
 sx.style.backgroud = colori[t];

你是说 .background 吗?

【讨论】:

  • 是的,有一些照片作为背景
  • 他告诉你你拼错了background
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 1970-01-01
  • 2014-07-25
  • 2014-04-21
  • 2019-05-04
相关资源
最近更新 更多