Javascript: innerHTML undefined



所以我正在做这样的事情...

var crypto = tradeMsg.coin
var oldPrice;
for (let i=0; i<500; i++) {
  var compare = cryptoSName[i].innerHTML
  if (compare == crypto) {
    document.getElementById('price' + i).innerHTML= "$" + (tradeMsg.message.msg.price.toFixed(4));;
    document.getElementById('perc' + i).innerHTML= tradeMsg.message.msg.perc + "%";
    var newPrice = tradeMsg.message.msg.price
    if (newPrice<oldPrice) {
      document.getElementById("cryptotable" + i).style.background = "#ffe5e5";
      console.log(oldPrice)
    }
    else if (newPrice>oldPrice) {
      document.getElementById("cryptotable" + i).style.background = "green";
    }
    console.log(oldPrice);
    console.log(newPrice);
    var oldPrice = tradeMsg.message.msg.price
    setTimeout(function() {
      document.getElementById("cryptotable" + i).style.background = "white"
    }, 1000);
  }
}

当我 console.log旧价格时,它显示不确定,而我期望在这里有先前的价值。我觉得我在这里升起时有问题。

如果有人可以在这里提供帮助,我会非常感激?

有人也可以解释我的意思。

JavaScript的示波器是功能级,而不是块级,并且创建 闭合只是意味着封闭范围被添加到 封闭功能的词汇环境

oldprice变量需要在初始时间内声明,然后检查

最新更新