2012-06-10 106 views
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。请帮助我背景图像不能在铬工作

+0

作品在这个例子中:http://jsfiddle.net/3JpLy/。 Chrome中的控制台中是否有任何错误日志? (按F12把它带到前面) –

+0

http://jsfiddle.net/QAUaz/似乎正常工作... – floorish

+0

会发生什么?该类本身的变化是否工作,背景图像是不是显示(错误的Url?)还是类的变化不起作用? – Chris

回答

2

该代码似乎很好,所以没有任何错误,它可能是铬重定向之前,它正在更改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 
}); 
+0

它工作正常。非常感谢你。 – khanh