gpt4 book ai didi

javascript - 外部 JS 在我的 html 文件中不起作用?

转载 作者:行者123 更新时间:2023-12-03 06:52:06 25 4
gpt4 key购买 nike

我对 JavaScript 还很陌生,我正在尝试将外部 JS 执行为 html,我想做的是查看当我的鼠标悬停在一个 img 上时鼠标悬停是否有响应。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GWW- A Global Warming Warning...</title>

<link href="style.css" rel="stylesheet">
</head>
<body>
<div class="gridContainer clearfix">
<div class="world">
<img src="poluicao/poluicao0001.png" alt="Mundo">
<div class="botao1">
<img src="poluicao/offbuton.png" alt="but1">
</div>
<div class="botao2">
<!--<a href="#" >//-->
<img id="readybotao" src="degelo/offbutton.gif" alt="but2">
<!-- </a> //-->
</div>
</div>

</div>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="javascript.js"</script>

</body>

</html>

这是我的 JS 文件:

function buttonon() {
alert("If it showed up it worked!");
}

document.getElementById('readybotao').addEventListener("onmousover",buttonon());

我做错了什么?

最佳答案

像这样更改外部 JavaScript :

var ele = document.getElementById("readybotao");
ele.addEventListener("mouseover",buttonon);
function buttonon() {
alert("If it showed up it worked!");
}

并关闭标签脚本:

 <script src="javascript.js"></script>

关于javascript - 外部 JS 在我的 html 文件中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37449623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com