繁体   English   中英

Javascript/jQuery - 当鼠标按下和抬起时更改输入按钮的背景图像

[英]Javascript/jQuery - Change input button the background image when mouse down and up

我想在鼠标按下和抬起时更改背景图像的输入按钮,但它不起作用。

在此处输入图片说明

 function mousedown() { document.getElementById("enlarge_btn").style.backgroundImage = "url(../picture/image2.svg)"; } function mouseup() { document.getElementById("enlarge_btn").style.backgroundImage = "url(../picture/image1.svg)"; }
 .button_img { width: 36px; height: 36px; background-image: url(../picture/image1.svg); background-color: transparent; background-size: cover; border: none; cursor: pointer; }
 <input id="enlarge_btn" type="button" name="button" class="button_img" onmousedown="mousedown()" onmouseup="mouseup()">

我在哪里可以修复?

请帮帮我,谢谢!

我发现如果我改变

document.getElementById("enlarge_btn").style.backgroundImage = "url(../picture/image2.svg)";

document.getElementById("enlarge_btn").style.backgroundImage = "url(picture/image2.svg)";

它有效,所以问题是文件路径。

谢谢。

暂无
暂无

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

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