鼠标按下时更改背景图像

2024-01-30

我有一个小问题,我发誓应该有用......这似乎是一个愚蠢的问题......但它是...... 我想要一个我创建的 div 来充当按钮......当我点击它时它不想改变它的背景(给出按钮的效果) 这是我的代码:

<!doctype html>
 <html>
 <head>
 <meta charset="utf-8">
 <title>Untitled Document</title>
 <style>
 #button1 {
     width:100px;
     height:50px;
     background-image:url(normalbutton.jpg)
 }
 </style>
 </head>

 <body class="asd">
 <div id="container">
 <a href="#">
 <div id="button1" onmousedown="document.getElementById("button1").style.backgroundImage='url(onmousedownbutton.jpg)'"></div></a>

 </body>
 </html>

我认为使用 jQuery 会很容易:

$("#button1").mousedown(function() {
    $(this).css({'background-image': 'url(1.jpg)'}) 
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

鼠标按下时更改背景图像 的相关文章