1
  .button {
        background: transparent url("/assets/LoD-Button-Normal.png") no-repeat bottom right;
        width: 110px;
        height: 30px;
        display: block;
        background-position: bottom right; 
        text-align:center;
    }

    .button_click { 
      background: transparent url("/assets/LoD-Button-Click.png") no-repeat bottom right;
      width: 110px;
      height: 30px;
      display: block;
      background-position: bottom right;
    }

    $(".button").click(function(){
      $(this).removeClass("button").addClass("button_click");   
    })

    <a class="button" href="/link"> Button </a>

当我单击按钮时。它在 Firefox 上更改背景图像,但在 chrome 上不起作用。请帮我

4

1 回答 1

2

该代码似乎很好,因此没有任何错误,可能是 chrome 在更改 bg 图像之前正在重定向。

试试这个:

$(".button").click(function(e){
  e.preventDefault();
  $(this).removeClass("button").addClass("button_click");
  location.href = $(this).attr('href'); 
  // if for some reason this isn't working you can call setTimeout with the location.href
});
于 2012-06-10T14:54:30.953 回答