我正在自定义 Sage CRM,因此我无法控制编写的 HTML,也无法将 ID 或类添加到 CRM 吐出的表格布局中。我想根据用户对选择下拉列表的选择隐藏更高(不是顶级)级别的表。我只能将 jQuery 选择器连接到我要隐藏的表中的表的标题行。
DOM 类似于:
//Lots of other table structures above this in the DOM....
<table> <---- this is the table I want to show or hide based on the users selection
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td class="PANEREPEAT"> <---- this is the node I can get selector to
Valuation information
////
所以我做了下面的客户端javascript:
var val_information_screen;
$('.PANEREPEAT').filter(function () {
//Find the valuation information screen
return $(this).text() == 'Valuation information';
}).each(function () { //iterate through all of these (there should only be one!)
val_information_screen = $(this);
});
var sel_ofee_type = $('#ofee_type');
if (sel_ofee_type.val() == '006') {
val_information_screen.closest('table').parents("table:first").show();
} else {
val_information_screen.closest('table').parents("table:first").hide();
}
它确实有效,只是不是特别漂亮。我真正讨厌的一点在下面。有没有更好的方法来使用 jQuery 遍历 DOM?
val_information_screen.closest('table').parents("table:first").show();
val_information_screen.closest('table').parents("table:first").hide();