layui table表格隐藏显示

image.png

image.png

<table class="layui-table" style="width: 98%;margin: 0 auto">
    <colgroup>
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th width="500">收款</th>
        <th width="500">1月</th>
        <th width="500">2月</th>
        <th width="500">3月</th>
        <th width="500">4月</th>
        <th width="500">5月</th>
        <th width="500">6月</th>
        <th width="500">7月</th>
        <th width="500">8月</th>
        <th width="500">9月</th>
        <th width="500">10月</th>
        <th width="500">11月</th>
        <th width="500">12月</th>
    </tr>
    </thead>
    <tbody>
    {foreach $array as $key}
    <tr class="text-c">
        <td class="pr" style="cursor: pointer;" id="{$key.id}" onclick="city($('.'+'{$key.id}'))">{$key.name}</td>
        {foreach $key.data as $k}
        <td>{$k}</td>
        {/foreach}

    </tr>
    {foreach $key.city as $k}
    <tr class="text-c {$key.id} city" style="display: none;">
        <td>{$k.name}</td>
        {foreach $k.data as $ke}
        <td>{$ke}</td>
        {/foreach}
    </tr>
    {/foreach}
    {/foreach}
    </tbody>
</table>
<script>
    $(function () {



        $('#search').click(function () {
            $.ajax({
                type: "post",
                url: "{:url('Reportform/czSearch')}",
                data: {
                    'campus': $('#xq').val(),
                    'czr': $('#czr').val(),
                    'sfxf': $('#sfxf').val(),
                    'add_time': $('#date').val()
                },
                async: true,
                success: function (i) {
                    $('#sk').html(i);
                }
            });
        })
    })


    function city(id) {
        if (id.css('display')=='none'){
            id.css('display','table-row')
        }else {
            id.css('display','none')
        }

    }
</script>

display:none //隐藏
display:table-row //显示

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。