我在表中使用了datatable脚本。这里我展示了产品清单。
下面是表的html代码(对于这个表我也应用了数据表脚本)
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="example" class="hovertable menuclass display">
<thead>
<th width="13%" style="padding-left:3px;">Actions</th>
<th width="21%">Name</th>
<th width="12%">col2</th>
<th width="18%">col3</th>
<th width="10%">col4</th>
<th width="7%">col5</th>
<th width="10%">col6</th>
<th width="5%" class="last">col7</th>
</thead>
<tr >
<td align="left" valign="top" style="width:95px;"><img src="images/minus_icon.png" alt="" border="0"> </td>
<td align="left" valign="top">name1</td>
<td align="left" valign="top">val</td>
<td align="left" valign="top">
value</td>
<td align="left" valign="top">tetse</td>
<td align="center" valign="top">test</td>
<td align="right" valign="top">test</td>
<td align="center" valign="top" class="last">241</td>
</tr>
<tr >
<td align="left" valign="top" style="width:95px;"><img src="images/minus_icon.png" alt="" border="0"> </td>
<td align="left" valign="top">name2</td>
<td align="left" valign="top">val</td>
<td align="left" valign="top">
value</td>
<td align="left" valign="top">tetse</td>
<td align="center" valign="top">test</td>
<td align="right" valign="top">test</td>
<td align="center" valign="top" class="last">241</td>
</tr>
</table>
我的表格行外观如下
当我点击' - '图像时,该行将被隐藏并显示为
如果我单击撤消链接,则再次显示相应的行。
我使用以下代码隐藏特定行。
$('.hdrow').live('click', function(){
$(this).closest('tr').toggle();
});
请参阅小提琴http://jsfiddle.net/2F2E5/2/
我不知道如何实现这一点。请帮我。感谢
答案 0 :(得分:1)
点击减号时尝试隐藏最近的行并保留一个td以显示隐藏的消息。
// Live is depreciated use new `on` method.
$(document).on('click','.minusSign',function(){
$(this).closest('tr').children().hide();
$(this).closest('tr').find('td.message').show();
// Assuming td.message is another table data with 'Product name is now hidden `undo`'
});
点击撤消隐藏消息td
并显示该行。
$(document).on('click','td.message a.undu',function(e){
e.preventDefault();
$(this).closest('tr').children().show();
$(this).closest('td.message').hide(); // Here `this` is undo link
});
这应该足够快。