【发布时间】:2017-05-24 00:26:06
【问题描述】:
由于某种原因,我每次尝试计算表中的行数 它总是返回 1。我正在动态添加和删除行到 表,所以我开始认为它只是在计算行数 最初配置在表中。这是我正在使用的代码。
$(".elementDelRowButton").live ('click', function (event) {
console.log ($(this).closest('table').length);
if ($(this).closest('tr').index()!=0) {
$(this).parent().parent().remove();
}
});
我尝试过使用大小、长度和其他变体,它总是返回 1。
这是 HTML:
<table id="element_items"><tr>
<td><input type="radio" name="radio" /></td>
<td><input type="text" value="RadioItem"/></td>
<td><span class="elementAddRowButton">+</span>/<span class="elementDelRowButton">-</span></td>
</tr>
</table>
【问题讨论】:
标签: jquery count html-table rows