简体   繁体   English

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

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

I'm doing a simple project with javascript and it requires me to get a value out of an HTML text input with javascript. 我正在用javascript做一个简单的项目,它要求我用javascript从HTML文本输入中获取值。 In the following code I've found that nothing after line 6 works and I have no idea why. 在下面的代码中,我发现在第6行之后没有任何工作,我不知道为什么。 This has been driving me crazy for like two hours and I'm kind of at my wits end. 这让我疯狂了两个小时,我有点在我的智慧结束。 Please help! 请帮忙!

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");
  }
}

It should be: 它应该是:

document.getElementById

instead of 代替

document.getElementByID

as Javascript is case sensitive. 因为Javascript区分大小写。

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

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