【发布时间】:2017-01-03 07:13:44
【问题描述】:
我有一张桌子,看起来像这样:
<table id="ctoTable" class="table table-bordered">
<thead> ... </thead>
<tbody>
<tr></tr>
<tr id="kpi#1" class="js-editable"></tr>
<tr id="kpi#2" class="js-editable"></tr>
<tr id="kpi#3" class="js-editable"></tr>
<tr id="kpi#4" class="js-editable"></tr>
<tr id="kpi#5" class="js-editable"></tr>
<tr id="kpi#6" class="js-editable"></tr>
<tr id="kpi#7" class="js-editable"></tr>
<tr id="kpi#8" class="js-editable"></tr>
<tr id="kpi#9" class="js-editable"></tr>
<tr id="kpi#76" class="js-editable"></tr>
<tr id="kpi#77" class="js-editable"></tr>
<tr></tr>
</tbody>
我想做某种过滤器,让我可以显示和隐藏一些行。我很确定我可以这样做,但不幸的是它不起作用。不仅我无法添加/删除类,我也无法获取 th 的属性。
jQuery(document).ready(function($) {
$( "#hideRows" ).click(function() {
var rows = $('.js-editable');
$.each(rows, function(index, item) {
console.log(item);
//item.addClass("hideElement"); //try to add the class to the tr
console.log(item.attr("id")); //try to print tr id in console
});
});
});
因此只有第一行会被打印出来
<tr id="kpi#1" class="js-editable"></tr>
并且该方法在没有记录任何错误的情况下中断。 有人可以向我解释这里发生了什么,我该如何解决这个问题。
【问题讨论】:
-
你能解释一下“方法中断但没有记录任何错误”是什么意思吗?它是如何打破的?您能否提供一个 JSFiddle 或 JSBin 示例,以便其他人可以验证“没有记录错误”。通常在您提供的示例中没有出现在 Promise 或错误的 try/catch 块中会发现错误吞咽。
-
不要制作带有八字形的 ID,这很愚蠢,我认为是错误的。
标签: javascript jquery html html-table