【问题标题】: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


    【解决方案1】:

    我想你想使用 mousedown 和 mouseup 事件。

    jQuery .mousedown()

    jQuery .mouseup()

    此外,如果您使用的是 jQuery 1.7 或更高版本,您应该开始使用/开始使用 on()off() 方法。

    【讨论】:

      【解决方案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')"); });
      

      【讨论】:

      • 通过投票表达你的爱 :)
      猜你喜欢
      • 1970-01-01
      • 2013-11-05
      • 2017-01-21
      • 2018-04-14
      • 2011-12-14
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      相关资源
      最近更新 更多