如何在html中的2个不同表的2个表头之间创建锚链接

时间:2013-08-01 19:11:36

标签: html html-table

在其中一个要求中,我们必须在html文档中构造许多表,并且顶部的表将包含行(类型为锚链接),每个行指向第二个表的标题直到最后一个表。顶表的第一行必须有锚标记指向第二个表的标题,顶表中的第二行应指向文档中第三个表的标题,顶表的最后一行应指向标题html文档中的最后一个表。

如何做到这一点?

1 个答案:

答案 0 :(得分:0)

这将完成这项工作,想想它是如何运作的。 Simply Link指向表格的id。

<html>
    <header></header>
    <body>
        <table>
            <caption>Main Table</caption>
            <tr>
                <th>ID</th>
                <th>Link</th>
            </tr>
            <tr>
                <td>1</td>
                <td><a href="#table1">Table 1</a></td>
            </tr>
            <tr>
                <td>2</td>
                <td><a href="#table2">Table 2</a></td>
            </tr>
        </table>

        <table id="table1">
            <caption>Table 1</caption>
            <tr>
                <th>Header 1</th>
                <th>Header 2</th>
            </tr>
            <tr>
                <td>Data</td>
                <td>Data</td>
            </tr>
            <tr>
                <td>Data</td>
                <td>Data</td>
            </tr>
        </table>

        <table id="table2">
            <caption>Table 2</caption>
            <tr>
                <th>Header 1</th>
                <th>Header 2</th>
            </tr>
            <tr>
                <td>Data</td>
                <td>Data</td>
            </tr>
            <tr>
                <td>Data</td>
                <td>Data</td>
            </tr>
        </table>
    </body>
</html>