将行插入带有文本输入的表中

发布于 2024-10-09 02:35:07 字数 1083 浏览 0 评论 0原文

我正在尝试在常规 HTML 表上插入行。

每行都有一个 元素。

但每次我通过 JavaScript 添加新行时,现有 中包含的数据或值都会消失。

代码如下:

<table id="tableSeriales" summary="Seriales" class="servicesT" cellspacing="0" style="width: 100%">
    <tr>
        <td class="servHd">Seriales</td>
    </tr>
    <tr>
     <td class="servBodL">
            <input id="0" type="text" value="" style="color: blue; width: 100%"/>
        </td>
    </tr>
</table>
<a href="javascript:addRow()">Add row</a> 

并且,JavaScript 如下所示:

function addRow() {
        var rowCount = $('#tableSeriales tr').length;
        $("#tableSeriales").html(
                $("#tableSeriales").html() +
                '<tr><td class="servBodL"><input id="' + (rowCount +1) + '"type="text" value="" style="color: blue; width: 100%" onkeypress="return handleKeyPress(event,this.form)"/></td></tr>'
            );
    }

I'm trying to insert a rows on a regular HTML table.

Each row has a <input type="text"> element.

But each time I add a new row through JavaScript, the data or values contained on the already existing <inputs> disappear.

Here's the code:

<table id="tableSeriales" summary="Seriales" class="servicesT" cellspacing="0" style="width: 100%">
    <tr>
        <td class="servHd">Seriales</td>
    </tr>
    <tr>
     <td class="servBodL">
            <input id="0" type="text" value="" style="color: blue; width: 100%"/>
        </td>
    </tr>
</table>
<a href="javascript:addRow()">Add row</a> 

And, the JavaScript looks like:

function addRow() {
        var rowCount = $('#tableSeriales tr').length;
        $("#tableSeriales").html(
                $("#tableSeriales").html() +
                '<tr><td class="servBodL"><input id="' + (rowCount +1) + '"type="text" value="" style="color: blue; width: 100%" onkeypress="return handleKeyPress(event,this.form)"/></td></tr>'
            );
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〗斷ホ乔殘χμё〖 2024-10-16 02:35:07

使用 $('html 代码在此处').appendTo('#tableSeriales');

$('#tableSeriales').append('html 代码在此处');

use $('html code goes here').appendTo('#tableSeriales');

or $('#tableSeriales').append('html code goes here');

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文