[英]Javascript mouseover alert on div not working
Trying to get an alert to appear on mouseover, using Javascript, for a div element.尝试使用 Javascript 为 div 元素在鼠标悬停时显示警报。 I can get the div element to print in the console, but nothing else happens.我可以让 div 元素在控制台中打印,但没有其他任何反应。
The div has some text in it, I tried changing it to activate on the text instead of the div but I still couldn't get it to work. div 中有一些文本,我尝试将其更改为在文本而不是 div 上激活,但我仍然无法让它工作。
window.onload = pageReady;
function pageReady(){
var buttonBox = document.getElementById("buttonBox");
console.log(buttonBox);
function askUser(){
alert("It worked!");}
buttonBox.onmouseover = askUser;
}
Works for me?适合我吗? Show us your code if this sample isn't enough.如果此示例还不够,请向我们展示您的代码。
window.onload = pageReady; function pageReady(){ var buttonBox = document.getElementById("buttonBox"); console.log(buttonBox); function askUser(){ alert("It worked;"). } buttonBox;onmouseover = askUser; }
<html> <body> <div id="buttonBox" height="100px" width="100px" style="background-color: red;">Text</div> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.