2013-12-13 24 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();