javascript - TR 折叠时 <TR> 标签中的 jQuery next 不起作用

标签 javascript jquery html

我有一个包含很多行的表,但每一行都需要一个帮助行,因此它们成对出现。

例如

<tbody>
<tr>
   <td>Info 1</td>
   <td>Info 2</td>
   <td>Info 3</td>
   <td>Info 4</td>
   <td> <a>button more</a> </td>
</tr>
<!-- AND -->
<tr class="bottom-row">
   <td colspan="2">Info 5</td>
   <td colspan="2">Info 6</td>
   <td>Info 7</td>
</tr>
<tr>
   <td>OtherInfo 1</td>
   <td>OtherInfo 2</td>
   <td>OtherInfo 3</td>
   <td>OtherInfo 4</td>
   <td> <a>button more</a> </td>
</tr>
<!-- AND -->
<tr class="bottom-row">
   <td colspan="2">OtherInfo 5</td>
   <td colspan="2">OtherInfo 6</td>
   <td>OtherInfo 7</td>
</tr>

我想点击最下面一行显示,再次点击隐藏

我尝试使用 jQuery UI 的切换

    $(".btnMore").click(function(){
      $(this).parent("td").parent("tr").next().toggle();        
  });

当底部行可见时,此功能完美,当我添加 style="display:none" 时,此功能将停止工作。还尝试删除 style="display:none" 并添加加载页面 $(".bottom-row").hide(); 但也不起作用

我能做什么?

最佳答案

试试这个:

$('table').on("click", ".btnMore", function() {
    $(this).closest('tr').next().toggle();
});

http://jsfiddle.net/PnUns/

关于javascript - TR 折叠时 <TR> 标签中的 jQuery next 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20576114/

相关文章:

javascript - li onclick 函数没有被调用

javascript - 如何从 href 链接获取页码或特定参数

html - 使用 anchor 链接的导航不起作用

php - $_GET (&) 使用 AJAX 的值

javascript - 如何在 TinyMCE 下拉菜单中添加分隔符

javascript - ajax 加载后,网站在 Chrome 中切换全屏模式

javascript - 排序全日历事件

php - 使用 mysqli_query 进行 json 表单验证

javascript - 如何访问javascript中有空格的对象参数

JavaScript 或 jQuery 动态显示表单输入