猿问

未捕获的 ReferenceError:sakla 未在 HTMLImageElement.

我是 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>

可能是什么问题呢?


慕哥6287543
浏览 165回答 2
2回答

慕斯王

试试下面的代码<html><head>&nbsp; &nbsp; <script type="text/javascript" src="jquery-3.4.1.min.js" />&nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; function hide() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // some actions&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; </script></head>&nbsp; &nbsp;&nbsp;<body>&nbsp; &nbsp; <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>

RISEBY

嘿伙计们,这里是答案,但我不知道为什么要写两次脚本标签。有人可以解释一下吗?<html><head>&nbsp; &nbsp; <script type="text/javascript" src="jquery-3.4.1.min.js" ></script>&nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; function hide() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var imgElem = $("#myImgId" );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log("bastın");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgElem.css({'display': 'none' })&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; </script></head>&nbsp; &nbsp;&nbsp;<body>&nbsp; &nbsp; <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>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答