2 回答

TA贡献1864条经验 获得超2个赞
试试下面的代码
<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>

TA贡献1856条经验 获得超5个赞
嘿伙计们,这里是答案,但我不知道为什么要写两次脚本标签。有人可以解释一下吗?
<html>
<head>
<script type="text/javascript" src="jquery-3.4.1.min.js" ></script>
<script>
function hide() {
var imgElem = $("#myImgId" );
console.log("bastın");
imgElem.css({'display': 'none' })
}
</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>
添加回答
举报