我正在尝试将元素的背景设置为 no-repeat
- 我已经尝试了以下方法,但它似乎什么也没做,我哪里出错了吗?它在 a
链接上显示图像,这很好。我正在使用 text-indent
隐藏文本链接以将其从页面上移除(隐藏它),但隐藏它也会隐藏背景图像。有没有办法试图隐藏链接并只显示 bg 图片?以下是我到目前为止所做的——我只需要一些指导来克服这个问题——对 jQuery 来说相对较新。
<script type="text/javascript"> //Looking for every td a element and alerting it out on page (popup)
$('.AspNet-DataList td a').each(function (index) {
//alert(index + ': ' + $(this).text());
var submitEl = $(".AspNet-DataList td a")
//.parent('.AspNet-DataList td a')
.css('background', 'url(/assets/img/radarstep' + (index + 1) + 'dark.png)', 'backgroundRepeat:', 'no-repeat');
});
当我在 firebug 中查看 td a
元素时,这是来自 jQuery css 的内容。即使从此处将背景设置为 no-repeat
也不起作用,并且在主 css 文件中我尝试添加高度和宽度 - 似乎不起作用。现在很困惑。
<a id="ctl07_HealthAndSafetyRadarForm_Wizard_SideBarContainer_SideBarList_SideBarButton_5" href="javascript:__doPostBack('ctl00$ctl07$HealthAndSafetyRadarForm_Wizard$SideBarContainer$SideBarList$ctl05$SideBarButton','')" style="background: url("/assets/img/radarstep6dark.png") no-repeat scroll 0 0 transparent;">Review</a>
//main.css
.AspNet-DataList td a {
/*text-indent: -9999em;*/
/*display:block; */
background-repeat: no-repeat;
height: 25px;
width: 25px;
}
最佳答案
.css({'background-image' : 'url(/assets/img/radarstep' + (index + 1) + 'dark.png)',
'background-repeat': 'no-repeat'});
关于jQuery .css 背景不重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8339551/