首页 > 解决方案 > 函数未定义 node.js 未捕获引用错误

问题描述

在我的 app.js 文件中,我定义了一个这样的函数:

function testfunc() {
    console.log("Testing");
}

在我的 home.html 文件中,我有这个:

<script type="text/javascript" src="./app.js"></script>

<div class="ProfileImage" onmouseover="testfunc()"> </div>

但是当我将鼠标悬停在 div 上时,它会产生这个

Uncaught ReferenceError: testfunc is not defined

这是我的文件结构:

在此处输入图像描述

标签: javascripthtmlnode.jsamazon-web-servicesamazon-ec2

解决方案


确保您的 HTML 文件遵循以下结构。我无法准确回答,因为我无法获取您的 JS 日志

<html>

<head>
  ...
</head>

<body>
  ...
  <div class="ProfileImage" onmouseover="testfunc()">abcdefg</div>
  <script>
    function testfunc() {
      console.log("Testing");
    }
  </script>
</body>

</html>


推荐阅读