2013-09-24 69 views
0

我有一些span标签,我们可以说#span具有属性background: url(some image) -22px top no-repeat的标识,它显示一些图像作为背景。 如果它有属性background: url(some image) -22px top no-repeat,则显示另一图像。问题是如果我指定('#span').attr('background-position','0px top')什么也没有发生,则不显示其他图像。有人能解释为什么吗?使用jQuery设置背景位置

回答

1

使用.css()

$('#span').css('background-position','0px top'); 

的CSS() - >获取样式属性的值对于该组匹配元件的第一元件。

+0

Oj的感谢你,我应该已经注意到, – user1611830

+0

我认为你可以在这里找到答案:http://stackoverflow.com/questions/1776950/change-background-position-with-jquery –

+1

@ user1611830欢迎。没关系你学会了一件新事物,开心:) –