首页 > 解决方案 > 未捕获的 ReferenceError:sakla 未在 HTMLImageElement.onclick 中定义

问题描述

我是 JavaScript 新手,我遇到了这个错误。下面是我的代码:

<html>
<head>
    <script type="text/javascript" src="jquery-3.4.1.min.js">
        function hide() {
            // some actions
        }
    </script>
</head>    
<body>
    <img id="myImgId" src="http://www.google.com/images/srpr/logo4w.png" onclick="hide()" style="position:absolute;opacity:0.5;left:50%;top:50%;width:50px;height:50px;margin-left:-25px;margin-top:-25px;z-index:100;"/>
</body>

可能是什么问题呢?

标签: javascriptjquery

解决方案


试试下面的代码

<html>
<head>
    <script type="text/javascript" src="jquery-3.4.1.min.js" />
    <script>
        function hide() {
            // some actions
        }
    </script>
</head>    
<body>
    <img id="myImgId" src="http://www.google.com/images/srpr/logo4w.png" onclick="hide()" style="position:absolute;opacity:0.5;left:50%;top:50%;width:50px;height:50px;margin-left:-25px;margin-top:-25px;z-index:100;"/>
</body>

推荐阅读