javascript - 未捕获的引用错误 - 未定义 functionName
问题描述
这是我的 HTML 文件
<!DOCTYPE html>
<html lang="e">
<head>
<meta charset="UTF-8">
<title> Practice Java Script </title>
<link rel="stylesheet" href="cssjs/csspracticejs.css">
<script scr="javajs/java.js"></script>
</head>
<body>
<h1>Changing the Style</h1>
<p>JavaScript can change the style of an HTML element.</p>
<button type="button" onclick="openMe()">Open!</button>
<button type="button" onclick="closeMe()">Close!</button>
<p id="demo">Extra details...You can open and close this paragraph using the
buttons above.</p>
</body>
</html>
这是我的 javascript
function closeMe(){
x=document.getElementById("demo");
x.style.display="none";
}
function openMe(){
x=document.getElementById("demo");
x.style.display="block";}
但是当我尝试运行它时,它显示为 Uncaught ReferenceError: closeMe is not defined at HTMLButtonElement.onclick (HTML.html:13)。你能帮忙看看我哪里做错了吗?
解决方案
导入脚本时出现拼写错误。
应该<script src>
不是<script scr>
。
推荐阅读
- wordpress - the_posts_pagination 在 wordpress 主页中不起作用
- hibernate - 使用 jpa 保存实体时出现“org.hibernate.TransientObjectException:代理未与会话关联”错误
- android - 如何不在 CalendarView 中设置默认日期?
- php - 如果它与字符串匹配,则从数组中删除值 - php
- angular - Angular 7:CustomMaterialModule 在 FeatureLazyLoadedModule 中不起作用
- php - 未定义变量:form_data (Laravel 5.7)
- javascript - 如何从这里获取 ajax url 成功函数值以全局使用 -> $('.demo').html(html);
- c# - C#中带参数的属性
- azure - 如何使用工作流在 Azure 上设计微服务系统以按顺序调用它们
- javascript - 通过 Web (javascript) 或独立 (Java) 将 ARCore Android 与桌面连接