在多个表中插入表格内容

时间:2018-03-07 07:24:54

标签: javascript php html html5 html-table

我有几个表,所有表都有不同的ID,但在不同的html页面上有相同的条目。是否可以仅在一个地方自动共享,然后将其调用(或回显)到其余页面中?

类似的东西:

<table id="table1">
    <thead>
        <tr>
            <th>Name</th>
        </tr>
    </thead>
    <tbody> 
        <tr>
            <td>John</td>       
        </tr>
        <tr>
            <td>Ida</td>
        </tr>
        <tr>
            <td>Thor</td>
        </tr>
        <tr>
            <td>Diana</td>  
        </tr>
        <tr>
            <td>Chris</td>
        </tr>
</table>

<table id="table2">
    <thead>
        <tr>
            <th>Name</th>
        </tr>
    </thead>
Insert tbody from table1
</table>

1 个答案:

答案 0 :(得分:0)

让你的第一张桌子成为,

首先在表1中的tbody中定义一个类是tableData1

    <table id="table1">
        <thead>
            <tr>
                <th>Name</th>
            </tr>
        </thead>
        <tbody class="tableData1"> 
            <tr>
                <td>John</td>       
            </tr>
            <tr>
                <td>Ida</td>
            </tr>
            <tr>
                <td>Thor</td>
            </tr>
            <tr>
                <td>Diana</td>  
            </tr>
            <tr>
                <td>Chris</td>
            </tr>
        </tbody>
    </table>

让表1插入另一个表2 tbody 2

<table id="table2">
    <thead>
        <tr>
            <th>Name</th>
        </tr>
    </thead>
<tbody class="tableData2"></tbody>
</table>

    $(document).ready(function(){   
    $('.tableData1').clone().insertAfter('.tableData2');
    })
相关问题