【问题标题】:Changing image while clicking/unclicking button单击/取消单击按钮时更改图像
【发布时间】:2012-01-21 11:53:03
【问题描述】:
谁能告诉我如何在单击按钮时动态更改按钮的图像?
我的代码:
$('.gamebox_minimap_plus').click(function() {
$(this).css("background-image","url('gfx/plus2.png')");
});
它在单击后工作,而不是在单击时工作,并且在我停止单击后不会返回到 plus1.png。
【问题讨论】:
标签:
javascript
jquery
image
button
【解决方案2】:
使用 mousedown 和 mouseup 代替点击。像这样:
$('.gamebox_minimap_plus').mousedown(function() { $(this).css("background- image","url('gfx/plus2.png')"); });
$('.gamebox_minimap_plus').mouseup(function() { $(this).css("background-image","url('gfx/plus1.png')"); });