javascript - 在 node.js 服务器中找不到 Javascript 函数
问题描述
我按照这个设置了 node.js 服务器:Using node.js as a simple web server
所以我安装了serve-static npm。
然后我使用以下代码创建了一个名为 test.html 的文件
<html>
<head>
<h2>Google</h2>
</head>
<body>
<button onclick="test()">Click me</button>
</body>
</html>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" type="text/javascript">
function test() {
console.log('test');
}
</script>
当我点击按钮时,我得到:
Uncaught ReferenceError: test is not defined
at HTMLButtonElement.onclick (test.html:8)
没有别的了。这段代码看起来不错...?为什么找不到这个功能?
解决方案
如果您想在标签src
之间拥有自己的功能,请删除您的部分。script
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
function test() {
console.log('test');
}
</script>
另外,你应该把你的脚本放在你的</body>
推荐阅读
- java - Tomcat打开文件过多错误(Ubuntu 18.04)
- php - 部署到 Heroku 时安装依赖项时出错
- codenameone - 代号一android在firebase上注册推送通知失败,返回INVALID_PARAETERS错误字符串
- javascript - 如何访问子组件的方法?
- javascript - 使用jquery避免在同一个表中重复数据
- python - 如何在 Django 1.11 的 Detailview 中添加类似的帖子
- java - 从活动移动到上一个片段
- c# - 与给定 SQL 查询等效的 LINQ MVC 查询是什么?
- python - 基于数值有条件地创建数据框列
- java - java.lang.NoClassDefFoundError - org/apache/spark/sql/hive/HiveContext