简体   繁体   English

检查Javascript代码“on mousedown”

[英]checking code of Javascript “on mousedown”

 <script> function lighton() { document.getElementById('myimage').src = "images\\download.png"; } function lightoff() { document.getElementById('myimage').src = "images\\link.png"; } </script> 
 <!DOCTYPE html> <html> <head> <script> function lighton() { document.getElementById('myimage').src = "images\\download.png"; } function lightoff() { document.getElementById('myimage').src = "images\\link.png"; } </script> </head> <body> <img id="myimage" onmousedown="lighton()" onmouseup="lightoff()" src="images\\link.png" width="100" height="180" /> <p>Click mouse and hold down!</p> </body> </html> 

see why this is not working when i click the mouse button first image disappears and second image does not open 当我点击鼠标按钮时,看到为什么这不起作用,第一张图像消失,第二张图像无法打开

I attached the event handers this way, and it started working. 我以这种方式附加了事件处理程序,它开始工作了。 Remember to do this after "onload". 记得在“onload”之后这样做。

var el = document.getElementById("myimage");
el.addEventListener("mousedown",lightoff);
el.addEventListener("mouseup",lighton);

The error I was seeing with your code was that it could not find the functions. 我用你的代码看到的错误是它找不到函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM