添加<;tr>&书信电报;td>;在表中未显示Javascript的div中
我有一个HTML表格,如下所示:添加<;tr>&书信电报;td>;在表中未显示Javascript的div中,javascript,jquery,html,html-table,append,Javascript,Jquery,Html,Html Table,Append,我有一个HTML表格,如下所示: <table> <tr> <th>Name</th> <th>Class</th> <th>Reg ID</th> </tr> <tr> <td>Alex</td>
<table>
<tr>
<th>Name</th>
<th>Class</th>
<th>Reg ID</th>
</tr>
<tr>
<td>Alex</td>
<td>VII</td>
<td>56733</td>
</tr>
<div id="addfield"></div>
</table>
<input type="button" value="add" id="add_more_fields" />
名称
等级
注册ID
亚历克斯
七
56733
以及jquery:
$(document).ready(function(){
var html = '';
$('#add_more_fields').click(function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('#addfield').append(html);
});
});
$(文档).ready(函数(){
var html='';
$(“#添加更多字段”)。单击(函数(){
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('#addfield').append(html);
});
});
我想将javascript生成的
添加到表中。但当我点击按钮时,输出显示在表外!如何在屏幕中显示它
桌子
试着用
tbody
代替#addfield
类似的
<table>
<thead>
<tr>
<th>Name</th>
<th>Class</th>
<th>Reg ID</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alex</td>
<td>VII</td>
<td>56733</td>
</tr>
</tbody>
</table>
名称
等级
注册ID
亚历克斯
七
56733
脚本
$('#add_more_fields').click(function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('tbody').append(html);
});
$('#添加更多字段')。单击(函数(){
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('tbody').append(html);
});
试着用
tbody
代替#addfield
类似的
<table>
<thead>
<tr>
<th>Name</th>
<th>Class</th>
<th>Reg ID</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alex</td>
<td>VII</td>
<td>56733</td>
</tr>
</tbody>
</table>
名称
等级
注册ID
亚历克斯
七
56733
脚本
$('#add_more_fields').click(function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('tbody').append(html);
});
$('#添加更多字段')。单击(函数(){
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('tbody').append(html);
});
试着用
tbody
代替#addfield
类似的
<table>
<thead>
<tr>
<th>Name</th>
<th>Class</th>
<th>Reg ID</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alex</td>
<td>VII</td>
<td>56733</td>
</tr>
</tbody>
</table>
名称
等级
注册ID
亚历克斯
七
56733
脚本
$('#add_more_fields').click(function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('tbody').append(html);
});
$('#添加更多字段')。单击(函数(){
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('tbody').append(html);
});
试着用
tbody
代替#addfield
类似的
<table>
<thead>
<tr>
<th>Name</th>
<th>Class</th>
<th>Reg ID</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alex</td>
<td>VII</td>
<td>56733</td>
</tr>
</tbody>
</table>
名称
等级
注册ID
亚历克斯
七
56733
脚本
$('#add_more_fields').click(function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('tbody').append(html);
});
$('#添加更多字段')。单击(函数(){
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('tbody').append(html);
});
它不起作用,因为
表中的div
是无效的HTML结构。将行追加到表本身
此外,您没有清除字符串html。这会导致多行
$('#add_more_fields').click(function () {
var html = ''; //declare string inside function
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('table').append(html);
});
$('#添加更多字段')。单击(函数(){
var html='';//在函数内声明字符串
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('table').append(html);
});
它不起作用,因为表中的div
是无效的HTML结构。将行追加到表本身
此外,您没有清除字符串html。这会导致多行
$('#add_more_fields').click(function () {
var html = ''; //declare string inside function
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('table').append(html);
});
$('#添加更多字段')。单击(函数(){
var html='';//在函数内声明字符串
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('table').append(html);
});
它不起作用,因为表中的div
是无效的HTML结构。将行追加到表本身
此外,您没有清除字符串html。这会导致多行
$('#add_more_fields').click(function () {
var html = ''; //declare string inside function
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('table').append(html);
});
$('#添加更多字段')。单击(函数(){
var html='';//在函数内声明字符串
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('table').append(html);
});
它不起作用,因为表中的div
是无效的HTML结构。将行追加到表本身
此外,您没有清除字符串html。这会导致多行
$('#add_more_fields').click(function () {
var html = ''; //declare string inside function
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('table').append(html);
});
$('#添加更多字段')。单击(函数(){
var html='';//在函数内声明字符串
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('table').append(html);
});
表中不能有div。你所要做的就是把身份证放在桌子上,然后取下div
<table id='addfield'>
表中不能有div。你所要做的就是把身份证放在桌子上,然后取下div
<table id='addfield'>
表中不能有div。你所要做的就是把身份证放在桌子上,然后取下div
<table id='addfield'>
表中不能有div。你所要做的就是把身份证放在桌子上,然后取下div
<table id='addfield'>
在表内追加
$('#add_more_fields').on('click',function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('table').append(html);//If you have more table then use id for table to append
});
$('add#more_fields')。在('click',function()上{
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('table').append(html);//如果您有更多的表,请使用id作为要追加的表
});
在表内追加
$('#add_more_fields').on('click',function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('table').append(html);//If you have more table then use id for table to append
});
$('add#more_fields')。在('click',function()上{
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('table').append(html);//如果您有更多的表,请使用id作为要追加的表
});
在表内追加
$('#add_more_fields').on('click',function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('table').append(html);//If you have more table then use id for table to append
});
$('add#more_fields')。在('click',function()上{
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('table').append(html);//如果您有更多的表,请使用id作为要追加的表
});
在表内追加
$('#add_more_fields').on('click',function(){
html += '<tr>';
html += '<td>Steve</td>';
html += '<td>X</td>';
html += '<td>87777</td>';
html += '</tr>';
$('table').append(html);//If you have more table then use id for table to append
});
$('add#more_fields')。在('click',function()上{
html+='';
html+='Steve';
html+='X';
html+='87777';
html+='';
$('table').append(html);//如果您有更多的表,请使用id作为要追加的表
});
我认为您需要将id提供给表
而不是Div
[Updated Fiddle]()我认为您需要将id提供给表