动态生成表格行中的表格 [英] Generating table inside a table row dynamically

查看:81
本文介绍了动态生成表格行中的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a web application, which uses HTML generic control to generate tables. I have a button in each row created dynamically. My question is, how can I add a new table under the corresponding row that holds the button?

推荐答案

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

Here is an example using jQuery, manipulating tables in pure JS in my experience is a bit clunky.

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

这篇关于动态生成表格行中的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆