javascript - 函数未定义 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
这是我的文件结构:
解决方案
确保您的 HTML 文件遵循以下结构。我无法准确回答,因为我无法获取您的 JS 日志
<html>
<head>
...
</head>
<body>
...
<div class="ProfileImage" onmouseover="testfunc()">abcdefg</div>
<script>
function testfunc() {
console.log("Testing");
}
</script>
</body>
</html>
推荐阅读
- javascript - 从 json 填充数据表(而不是从 ajax)
- c# - 选择“在网络部署上发布”选项时,如何防止 Visual Studio 自动发布我的源代码?
- javascript - 避免 & 在 ng-select 角度 7 中的下拉菜单
- xamarin - 将 MainActivity 的代码放在 Xamarin 表单中的另一个类或内容页面的哪里?
- .htaccess - .htaccess 的热链接保护不起作用
- ruby-on-rails - 如何在不使用 ruby on rails 中的设计提交密码更改表单的情况下不重定向到另一个表单?
- android - 如何在 json 对象响应中解析 json 数组?
- c++ - 如何获取其他人可以用来连接到我在 C++ 中构建的套接字的 IP
- php - 如何根据php中的另一个键找到多维数组中的最大日期?
- visual-studio-code - vscode markdown sparql 语法高亮在受保护的代码块中