繁体   English   中英

使用document.getElementByID从文本输入中获取值不起作用

[英]Getting value from text input using document.getElementByID not working

我正在用javascript做一个简单的项目,它要求我用javascript从HTML文本输入中获取值。 在下面的代码中,我发现在第6行之后没有任何工作,我不知道为什么。 这让我疯狂了两个小时,我有点在我的智慧结束。 请帮忙!

function letsPlayAGame() {
  var answer = Math.floor(Math.random() * 100 + 1);

  var guess = document.getElementByID("theinput").value;

  if (Number.isInteger(guess) == false) {
    document.getElementByID("label").innerHTML =
      "Please enter a number between 1 and 100!";
  } else if (guess < 1 || guess > 100) {
    document.getElementByID("label").innerHTML =
      "Please enter a number between 1 and 100!";
  } else {
    alert("not this part");
  }
}

它应该是:

document.getElementById

代替

document.getElementByID

因为Javascript区分大小写。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM