Javascript 在从表追加到另一个表时添加额外列
在这里,我试图从一个表(3列)附加到另一个表。这很好。我需要一些额外的专栏。谁能帮帮我吗。我的片段Javascript 在从表追加到另一个表时添加额外列,javascript,jquery,html,Javascript,Jquery,Html,在这里,我试图从一个表(3列)附加到另一个表。这很好。我需要一些额外的专栏。谁能帮帮我吗。我的片段 function table2(){ $('#one').on("click", function(){ $('#one tbody input:checked').parent().parent().appendTo("#two"); } 这可能会有帮助,这是一个例子 // First of all this is an example, you has to modify th
function table2(){
$('#one').on("click", function(){
$('#one tbody input:checked').parent().parent().appendTo("#two");
}
这可能会有帮助,这是一个例子
// First of all this is an example, you has to modify this make as you wish
// Here we can add dynamic columns & rows
// Also , I have given an option to specify the row/column name
<table border="1" id="mtable">
<thead>
<tr>
<td>Item</td><td>Red</td><td>Green</td>
</tr>
</thead>
<tbody>
<tr>
<td>Some Item</td><td><input type="checkbox"/></td><td><input type="checkbox"/></td>
</tr>
</tbody>
</table>
<br/><br/>
<input id="row" placeholder="Enter Item Name"/><button id="irow">Insert Row</button><br/><br/>
<input id="col" placeholder="Enter Heading"/><button id="icol">Insert Column</button>
<script>
// This is add additional row to a table
$('#irow').click(function(){
if($('#row').val()){
// Creates a copy of last row and you specify the name of row as well as
// each <td>. Here I'm given a checkbox.
$('#mtable tbody').append($("#mtable tbody tr:last").clone());
$('#mtable tbody tr:last :checkbox').attr('checked',false);
$('#mtable tbody tr:last td:first').html($('#row').val());
}else{alert('Enter Text');}
});
$('#icol').click(function(){
// This is add additional column to a table
if($('#col').val()){
// This is to append/add column to a table
$('#mtable tr').append($("<td>"));
$('#mtable thead tr>td:last').html($('#col').val());
// This is to add a column to each rows in a table
$('#mtable tbody tr').each(function(){
$(this).children('td:last').append($('<input type="checkbox">'));
});
} else { alert('Enter Text'); }
});
</script>
//首先,这是一个示例,您必须根据需要修改此make
//在这里,我们可以添加动态列和行
//此外,我还提供了一个选项来指定行/列名
项目红绿色
某项
插入行
插入列
//这是向表中添加其他行
$('#irow')。单击(函数(){
if($('#行').val()){
//创建最后一行的副本,并指定行的名称以及
//每个。这里给我一个复选框。
$(“#mtable tbody”).append($(“#mtable tbody tr:last”).clone();
$('#mtable tbody tr:last:checkbox').attr('checked',false);
$('#mtable tbody tr:last td:first').html($('#row').val());
}else{alert('entertext');}
});
$('#icol')。单击(函数(){
//这是向表中添加其他列
if($('#col').val()){
//这是向表中追加/添加列
$('#mtable tr')。追加($(“”);
$('#mtable thead tr>td:last').html($('#col').val());
//这是向表中的每一行添加一列
$('#mtable tbody tr')。每个(函数(){
$(this.children('td:last')。追加($('');
});
}else{alert('entertext');}
});
这可能会有所帮助,这是一个示例
// First of all this is an example, you has to modify this make as you wish
// Here we can add dynamic columns & rows
// Also , I have given an option to specify the row/column name
<table border="1" id="mtable">
<thead>
<tr>
<td>Item</td><td>Red</td><td>Green</td>
</tr>
</thead>
<tbody>
<tr>
<td>Some Item</td><td><input type="checkbox"/></td><td><input type="checkbox"/></td>
</tr>
</tbody>
</table>
<br/><br/>
<input id="row" placeholder="Enter Item Name"/><button id="irow">Insert Row</button><br/><br/>
<input id="col" placeholder="Enter Heading"/><button id="icol">Insert Column</button>
<script>
// This is add additional row to a table
$('#irow').click(function(){
if($('#row').val()){
// Creates a copy of last row and you specify the name of row as well as
// each <td>. Here I'm given a checkbox.
$('#mtable tbody').append($("#mtable tbody tr:last").clone());
$('#mtable tbody tr:last :checkbox').attr('checked',false);
$('#mtable tbody tr:last td:first').html($('#row').val());
}else{alert('Enter Text');}
});
$('#icol').click(function(){
// This is add additional column to a table
if($('#col').val()){
// This is to append/add column to a table
$('#mtable tr').append($("<td>"));
$('#mtable thead tr>td:last').html($('#col').val());
// This is to add a column to each rows in a table
$('#mtable tbody tr').each(function(){
$(this).children('td:last').append($('<input type="checkbox">'));
});
} else { alert('Enter Text'); }
});
</script>
//首先,这是一个示例,您必须根据需要修改此make
//在这里,我们可以添加动态列和行
//此外,我还提供了一个选项来指定行/列名
项目红绿色
某项
插入行
插入列
//这是向表中添加其他行
$('#irow')。单击(函数(){
if($('#行').val()){
//创建最后一行的副本,并指定行的名称以及
//每个。这里给我一个复选框。
$(“#mtable tbody”).append($(“#mtable tbody tr:last”).clone();
$('#mtable tbody tr:last:checkbox').attr('checked',false);
$('#mtable tbody tr:last td:first').html($('#row').val());
}else{alert('entertext');}
});
$('#icol')。单击(函数(){
//这是向表中添加其他列
if($('#col').val()){
//这是向表中追加/添加列
$('#mtable tr')。追加($(“”);
$('#mtable thead tr>td:last').html($('#col').val());
//这是向表中的每一行添加一列
$('#mtable tbody tr')。每个(函数(){
$(this.children('td:last')。追加($('');
});
}else{alert('entertext');}
});
进一步解释您的问题,您希望向exist表和以前创建的新表添加行。是吗?是的。。这就是我需要的。。我有专栏标题。现在我需要添加行或单元格@ToujouAyaok,检查这个,进一步解释你的问题,你想添加行到exist表和之前创建的新表。是吗?是的。。这就是我需要的。。我有专栏标题。现在我需要添加行或单元格@ToujouAyaok,检查这个你不认为解释它为什么有用,或者解释源代码以便其他人能够理解它的功能是一个好主意吗?如果你把它变成一个工作片段并解释源代码,我会很乐意给出答案,但从目前的情况看,这看起来只是一个复制/粘贴,希望他们能找到它的用途。有些人寻求帮助,但也希望了解解决方案/源代码,而不仅仅是复制/粘贴,此外,它还可以帮助其他遇到类似问题的人。当然会解释这一点。您也可以查看文档。您不认为解释它为什么有用,或者解释源代码以便其他人能够理解它的功能是一个好主意吗?如果你把它变成一个工作片段并解释源代码,我会很乐意给出答案,但从目前的情况看,这看起来只是一个复制/粘贴,希望他们能找到它的用途。有些人寻求帮助,但也希望了解解决方案/源代码,而不仅仅是进行复制/粘贴,它还可以帮助其他遇到类似问题的人。当然会解释这一点。您也可以查看文档。