将行插入带有文本输入的表中
我正在尝试在常规 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
$('html 代码在此处').appendTo('#tableSeriales');
或
$('#tableSeriales').append('html 代码在此处');
use
$('html code goes here').appendTo('#tableSeriales');
or
$('#tableSeriales').append('html code goes here');