[英]Add Event Listener on Javascript
I'm new to javascript and can't figure out why the following code isn't working: 我是javascript新手,无法弄清楚以下代码为何不起作用:
var toChange = document.getElementById("greeting"); toChange.addEventListener("mouseOver", function() { this.innerHTML = "Hi"; });
<p id="greeting">Hello.</p>
I've thoroughly researched event listeners, and I can't figure out why this code won't work. 我已经对事件侦听器进行了深入的研究,我不知道为什么此代码无法正常工作。 Thank you.
谢谢。
Event names are case-sensitive. 事件名称区分大小写。 Here's your code, with
mouseOver
replaced with mouseover
. 这是您的代码,其中
mouseOver
替换为mouseover
。
var toChange = document.getElementById("greeting"); toChange.addEventListener("mouseover", function() { this.innerHTML = "Hi"; });
<p id="greeting">Hello.</p>
请改用小写的"mouseover"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.