2013-12-13 85 views
2

我有很多行的表,但各行需要帮助排,所以它们是成对出现的。jQuery的未来在<TR>标签不工作时,TR崩溃

例如

<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();但不起作用要么

我可以做什么?

+0

隐藏的行不应该改变不是它是其他的功能首先隐藏。你确定添加这种风格没有导致无效的HTML由于错字? –

+0

我看到一类btnMore的任何元素,你的'$(“ btnMore”)'选择在你的例子匹配。 – j08691

+0

创建jsfiddle.net是复制problem.Nothing在你的代码演示显示'显示:none' – charlietfl

回答

3

试试这个:

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

http://jsfiddle.net/PnUns/

+0

非常感谢您的支持,但是,无论是回答对我的作品,就像我的问题是我的CSS,但我不能修改enterpress rulez。任何mod都可以关闭这个问题。 – jasilva

0

这似乎很好地工作,当我尝试它,http://jsfiddle.net/LF7Ar/1/

// I added the hide from the beginning 
$(".btnMore").click(function(){ 
    $(this).parent("td").parent("tr").next().toggle();   
}); 
$('.bottom-row').hide();