簡體   English   中英

在多個表中插入表內容

[英]Insert table content in several tables

我有幾個表,每個表都有不同的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的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');
    })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM