繁体   English   中英

如何隐藏除 Javascript/JQuery 和 CSS 中的第一个孩子之外的所有孩子?

[英]How do I hide all children except the for the first child in Javascript/JQuery and CSS?

HTML:

<table id="collapse">
    <tbody>
        <tr>
            <th>Heading</th>
        </tr>
        <tr>
            <td>Text</td>
        </tr>
        <tr>
            <td>Text</td>
        </tr>
     </tbody>
</table>

Javascript/JQuery:

<script type="text/javascript">
    $(document).ready(function()
    {
        $('#collapse');
    });
</script>

CSS:

<style type="text/css">
    #collapse tr{display:none;}
    #collapse tr:first-child{display:table-row;}

    /* or is there a prettier, better way to do this? */
</style>

如何在页面加载时隐藏除 Javascript/JQueryCSS 中的第一个孩子之外的所有孩子?

所以,它实际上应该只显示:

<table id="collapse">
    <tbody>
        <tr>
            <th>Heading</th>
        </tr>
     </tbody>
</table>

注意:我不想像.hide_child{display:none;}

<script type="text/javascript">
    $(document).ready(function()
    {
        $('#collapse tr').not(":first-child").hide();
    });
</script>

见: http://jsfiddle.net/FeVnt/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM