我有以下html标记:
<table class="rwTitlebarControls" cellspacing="0" cellpadding="0" align="left">
<tbody>
<tr>
<td style="width: 16px;">
<a class="rwIcon" style="background: transparent url(Images/ic_icon_16.png) no-repeat scroll 0px 0px; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"/>
</td>
<td>
<em unselectable="on">Title</em>
</td>
<td nowrap="" style="white-space: nowrap;">
</td>
</tr>
</tbody>
</table>
我想使用jQuery使用类 rwIcon 更改&lt; a&gt; -element的图片网址,但我似乎无法找到.rwIcon。
我可以使用以下方法找到包含表格:
$('table.rwTitlebarControls');
但以下两个选项都无法返回我需要的元素
$('a.rwIcon')
$('.rwIcon')
我做错了什么?
注意:此HTML由Telerik的RadComponents自动生成,而不是我可以更改或控制的内容,因此请尝试回答问题并避免评论标记的质量。谢谢!
答案 0 :(得分:2)
这确实有效:
$('.rwIcon')
但是该类的标签是空的(即它没有内容)
这有效:
<a class="rwIcon" style="background: transparent url(Images/ic_icon_16.png) no-repeat scroll 0px 0px; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">SOME CONTENT</a>
使用此脚本:
$(".rwIcon").css({backgroundColor:"#000000"});
答案 1 :(得分:0)
原来我有正确的元素,我只是没有识别它。以下脚本更改了a-tag的背景图像:
function ChangeWindowIcon(icon) {
icon = 'url(Images/ic_' + icon + '_16.png)';
$('a.rwIcon').css({ 'background-image': icon });
}