TypeError: input.includes is not a function

TypeError: input.includes is not a function

所以我正在制作一个简单的脚本来检查输入字段是否包含“@”,但是每当我 运行 下面的代码时,我都会收到以下错误:TypeError: input.includes is not a功能。

代码:

function check() {
    var input = document.getElementById('input');

    if(input.includes("@")) {
        alert("Success!!");
    }
}

这是我的 html 如果有帮助的话:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>opdracht3</title>
</head>
<body>
    <form>
        <input type="text" id="input">
        <input type="button" value="Go" onclick="check()"></button>
    </form>

    <script src="opdracht3.js"></script>
</body>
</html>

您需要输入的值。将 .value 添加到您的代码中:

function check() {
  var input = document.getElementById('input');

  if (input.value.includes("@")) {
    alert("Success!!");
  }
}
<form>
  <input type="text" id="input">
  <input type="button" value="Go" onclick="check()"></button>
</form>