我有代码
<table id="financial101_tab1" class="dxrpControl_Moderno dxrpWithoutHeader_Moderno" style="border-collapse: separate; opacity: 1; margin-left: 0px;">
<tbody>
<tr>
<td id="financial101_tab1_RPC" class="dxrp dxrpcontent" style="padding: 6px 10px 10px; border-width: medium; border-style: …r-color: -moz-use-text-color; background-color: transparent;">
<input id="BlockControlfinancial101_tab1ATI" type="hidden" value="1" name="BlockControlfinancial101_tab1ATI"></input>
<div id="BlockControlfinancial101_tab1" class="dxtcLite_Moderno dxtc-top" style="">
<ul id="BlockControlfinancial101_tab1_TC" class="dxtc-strip dxtc-stripContainer" style="padding: 3px 0px 0px; width: 624px;"></ul>
<div id="BlockControlfinancial101_tab1_CC" class="dxtc-content" style="visibility: visible; width: 600px;"></div>
<input type="hidden" name="BlockControlfinancial101_tab1_DXState" value="{"t":[]}"></input>
</div>
<b class="dx-clear"></b>
<script id="dxss_1482507144" type="text/javascript"></script>
</td>
</tr>
</tbody>
有6个表,
我希望按类名.dxrpControl_Moderno.dxrpWithoutHeader_Moderno
获取所有元素,因为它们在6 t表中是相同的,并且设置它的孩子#BlockControlfinancial101_tab2_AT0
背景,已经有
$(".dxrpControl_Moderno.dxrpWithoutHeader_Moderno").each(function () {
if ($(".dxrpControl_Moderno.dxrpWithoutHeader_Moderno").find(".dxtc-text.dx-vam").text() == "Гистограмма") {
$(".dxrpControl_Moderno.dxrpWithoutHeader_Moderno").find("#BlockControlfinancial101_tab2_AT0").css('background', 'url(../../CustomStyleSource/icons/chart_bar_icon24.png) no-repeat center center');
}
});
遗憾的是,它没有用,有什么想法吗?
答案 0 :(得分:0)
您需要使用$(this)
定位每个循环中的当前.dxrpControl_Moderno.dxrpWithoutHeader_Moderno
:
$(".dxrpControl_Moderno.dxrpWithoutHeader_Moderno").each(function () {
if ($(this).find(".dxtc-text.dx-vam").text().trim() == "Гистограмма") {
$(this).find(".BlockControlfinancial101_tab2_AT0").css('background', 'url(../../CustomStyleSource/icons/chart_bar_icon24.png) no-repeat center center');
}
});
此外,id
是唯一的,您应该使用类,因此您需要更改:
id="BlockControlfinancial101_tab2_AT0"
为:
class="BlockControlfinancial101_tab2_AT0"
为您的元素。