【问题标题】:Generating table inside a table row dynamically动态生成表格行内的表格
【发布时间】:2013-02-19 15:50:34
【问题描述】:

我有一个 Web 应用程序,它使用 HTML 通用控件来生成表格。我在动态创建的每一行中都有一个按钮。我的问题是,如何在包含按钮的相应行下添加一个新表?

【问题讨论】:

  • 所以你已经有了动态生成表的代码,为什么还要坚持创建另一个表?

标签: javascript c# html html-table


【解决方案1】:

这是一个使用 jQuery 的示例,以我的经验在纯 JS 中操作表格有点笨拙。

See on jsFiddle

HTML

<table>
    <tr>
        <td><button class="add-table">Add table</button></td>
    </tr>
    <tr>
        <td><button class="add-table">Add table</button></td>
    </tr>
</table>

jQuery

$(document).ready(function () {
    $('.add-table').click(function () {
        $(this).after('<table>\
            <tr>\
            <td>New table</td>\
            </tr>\
            </table>');
    });
});

【讨论】:

    猜你喜欢
    • 2013-09-22
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 2018-01-15
    • 2020-10-17
    • 1970-01-01
    相关资源
    最近更新 更多