Web浏览器未显示输出

Web-browser is not showing the output

本文关键字:输出 显示 浏览器 Web      更新时间:2023-09-26

我是JavaScript新手,已经遇到了一个问题。当我运行代码并弹出浏览器时,它[浏览器]不会显示任何内容。我有一个testMethod.js文件,它有一种方法:

function testMethod(num1, num2){
    var value = num1 + num2;
    return value;
}

和一个我试图运行的HTML文件:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title> My JavaScript</title>
    <script language = "javascript" src = testMethod.js"></script>
</head>
<body>
  <script language = "javascript" type = "text/javascript">
    // var getValue = testMethod(2,3);
      document.write("The result is " + testMethod(5,3));

  </script>
  <noscript>
      <h3> This site requires JavaScript</h3>
  </noscript>
</body>
</html>

代码根本没有实现结果。它只显示一个空白页面浏览器。

html中似乎缺少一个引号,应该是src="testMethod.js",您首先要在其中包含脚本。