首页 > 解决方案 > 未捕获的引用错误 - 未定义 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)。你能帮忙看看我哪里做错了吗?

标签: javascripthtml

解决方案


导入脚本时出现拼写错误。

应该<script src>不是<script scr>


推荐阅读