【发布时间】:2017-09-11 04:47:33
【问题描述】:
我正在尝试在 html 表格行上使用显示/隐藏机制。当我双击表格行时,它添加了detail 类,其余表格行被隐藏。
代码如下:
<table class='container'>
<tr>
<th>ID</th>
<th>ID1</th>
<th>Title</th>
</tr>
<tr id='7305' class='testtr'>
<td>7305</td>
<td>7305</td>
<td>Title1</td>
</tr>
<tr id='7381' class='testtr'>
<td>7381</td>
<td>7381</td>
<td>Title2</td>
</tr>
<tr id='8573' class='testtr'>
<td>8573</td>
<td>8573</td>
<td>Title3</td>
</tr>
</table>
第一步有效,但我无法自己修复第二步。这样做:
<script>
$(function () {
$("table").colResizable({ liveDrag: true });
});
$('.testtr').dblclick(function () {
$('.testtr').hide();
$('.testtr').not(this).addClass('hidden');
$(this).show();
});
$('.testr.detail').dblclick(function () {
$('hidden').toggle();
$(this).removeClass('detail');
});
</script>
就像我说的,我可以隐藏除一个以外的所有行...但我无法取消隐藏隐藏的行。你能帮忙吗?
【问题讨论】:
-
.testr.detail- 是错字吗?此外,它也不起作用,因为在执行脚本时.testtr.detail不存在(我假设它是在页面加载时执行的)。使用类似$(document).on('dblclick', '.testtr.detail', function(){...}) -
使用
$('.hidden').toggle();而不是$('hidden').toggle();