【问题标题】:Insert table content in several tables在多个表格中插入表格内容
【发布时间】:2018-03-08 00:34:19
【问题描述】:

我有几个表格,所有表格都有不同的 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>

【问题讨论】:

  • 您可以使用克隆选项完成表

标签: javascript php html html-table


【解决方案1】:

让你的第一张桌子成为,

首先在表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');
    })

【讨论】:

  • 嗨 Whoami,我不知道我做错了什么,但你的代码不适合我。我试图在同一个html页面中插入上面的两个表,但是第二个表是空的???
  • @J.Birch,你是否创建了 类?
  • 我正在对您上面的代码进行精确复制。你是这个意思吗?抱歉,我是 html 编码的新手。
  • 你是否包含了jquery cdn
  • 我在中加入了“
猜你喜欢
相关资源
最近更新 更多
热门标签