简体   繁体   English

如何再次使用按钮追加同一张表,以及如何在另一张表中排行该表的数据

[英]How to append same table again with button and how to row data of table in another tables

I have developed a form where I am using some tables to get data where some key points related to these tables are:- 我已经开发了一种表格,其中使用一些表格来获取数据,其中一些与这些表格有关的关键点是:

  1. "AddNew2" button is for adding one more table like table 2 . “ AddNew2”按钮用于添加另一个表,如表2。 Number of rows in Table 2 and all other tables added by using Addnew2 button will be increase if i click "AddNew1" Button of Table 1. 如果我单击表1的“ AddNew1”按钮,表2和使用Addnew2按钮添加的所有其他表中的行数将会增加。

  2. Table 1 is master table of getting same employee name is all tables. 表1是得到相同雇员姓名的主表是所有表。 which means if I click "AddNew1" button then there will new row added in table 1 , table 2 and other tables and whatever employee name i am tyoing in table 1 will be copy in same in table 2 and other tables. 这意味着如果我单击“ AddNew1”按钮,那么将在表1,表2和其他表中添加新行,并且我在表1中使用的任何员工姓名都将在表2和其他表中被复制。

But I am facing some issues which are:- 但是我面临的一些问题是:

  1. Whatever employee name i am typing in table 1, is coming perfectly in table 2 but it is not coming in table 3 , table 4 (which I added by clicking AddNew2 button.) 我在表1中键入的任何员工姓名都很好地出现在表2中,但没有出现在表3中,表4中(我通过单击AddNew2按钮将其添加。)

  2. If I click AddNew1 button to add new row in table 1 , than one more row is increasing in Table 2 (say now table 1 and table 2 has 2-2 row). 如果我单击AddNew1按钮在表1中添加新行,则表2中的行将增加(现在说表1和表2具有2-2行)。 but now if I click in AddNew2 button to add same table like Table 2 than that Table is coming with only one table. 但是现在,如果我单击AddNew2按钮添加与表2相同的表,则该表仅包含一个表。

I am not able to solve this issue. 我无法解决此问题。 I have added my code here as well please have a look. 我也在这里添加了我的代码,请看看。

 $(document).ready(function() { $("#insert66").click(function() { $(".copySubName tbody").append('<tr> <td> <input type="text" class="form-control EmpName" name="EmpName"> </td></tr>') $("#tableboth tbody").append('<tr> <td> <input type="text" class="form-control EmpName" disabled="true" name="EmpName"> </td> <td> <input type="text" class="form-control years allownumericwithoutdecimal" maxlength="3" name="years"> </td> <td> <input type="checkbox" id="mandatorySub"> </td> </tr>') }); $('.copySubName').on('input', '.EmpName', function() { var index = $(this).closest('table').find('input').index(this); //for second table $('#tableboth').find('.EmpName').eq(index).val($(this).val()) //for 3rd table }); }); $("#insert17").click(function() { $(".individualSalSection").append(' <div class="portlet-body individual individualMarksSectionSub"><label class="label1 col-md-12 individual labelBoardName" style="display:none"> Enter Board Name </label><input type="text" class="form-control individual boardName"></input> <table id="tableboth" class="arrSubjects table table-striped table-hover arrSubjects individual"> <thead> <th>Employee</th> <th> Marks</th> <th> is mandatory</th> </thead> <tbody> <tr> <td> <input type="text" class="form-control EmpName" disabled="true" name="subject1"> </td> <td> <input type="text" class="form-control years allownumericwithoutdecimal" maxlength="3" name="years"> </td> <td> <input type="checkbox" id="mandatorySub"> </td> </tr> </tbody></table></div>') }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> Table 1:- <table id="table66" class="table table-bordered table-hover copySubName"> <input type="button" class="btn green" value="Add New+" id="insert66"></input> <thead> <th>Employee Name</th> </thead> <tbody> <tr> <td> <input type="text" class="form-control EmpName" name="EmpName"> </td> </tr> </tbody> </table> <div class="portlet light portlet-fit box individual individualSalSection"> <input type="button" class="btn green individual" value="Add New+" id="insert17"></input> <div class="portlet-body individual individualSalSectionSub"> <label class="label1 col-md-12 individual labelBoardName" style="display:none"> Enter Board Name </label> <input type="text" class="form-control individual boardName"></input> Table2: <table id="tableboth" class="arrSubjects table table-striped table-hover arrSubjects individual"> <thead> <th>Employee</th> <th> Marks</th> <th> is mandatory</th> </thead> <tbody> <tr> <td> <input type="text" class="form-control EmpName" disabled="true" name="EmpName"> </td> <td> <input type="text" class="form-control years allownumericwithoutdecimal" maxlength="3" name="years"> </td> <td> <input type="checkbox" id="mandatorySub"> </td> </tr> </tbody> </table> </div> </div> 

As your question is not clear, so I am not sure what should be the correct solution, for you, please try below code and check whether you are looking for this. 由于您的问题尚不清楚,因此我不确定哪种方法是正确的解决方案,请尝试以下代码并检查您是否正在寻找此方法。 I have added each method to add employee name in new tables as well - 我还添加了每种方法来在新表中添加员工姓名-

Fiddle 小提琴

 $(document).ready(function() { $("#insert66").click(function() { $(".copySubName tbody").append('<tr> <td> <input type="text" class="form-control EmpName" name="EmpName"> </td></tr>') $("#tableboth tbody").append('<tr> <td> <input type="text" class="form-control EmpName" disabled="true" name="EmpName"> </td> <td> <input type="text" class="form-control years allownumericwithoutdecimal" maxlength="3" name="years"> </td> <td> <input type="checkbox" id="mandatorySub"> </td> </tr>') }); $('.copySubName').on('input', '.EmpName', function() { var index = $(this).closest('table').find('input').index(this); var that = $(this); //for second table $('.tableboth').each(function(index,obj){ $(obj).find('.EmpName').val(that.val())}) //for 3rd table }); }); $("#insert17").click(function() { $(".individualSalSection").append(' <div class="portlet-body individual individualMarksSectionSub"><label class="label1 col-md-12 individual labelBoardName" style="display:none"> Enter Board Name </label> <table class="tableboth" class="arrSubjects table table-striped table-hover arrSubjects individual"> <thead> <th>Subject</th> <th> Marks</th> <th> is mandatory</th> </thead> <tbody> <tr> <td> <input type="text" class="form-control EmpName" disabled="true" name="subject1"> </td> <td> <input type="text" class="form-control years allownumericwithoutdecimal" maxlength="3" name="years"> </td> <td> <input type="checkbox" id="mandatorySub"> </td> </tr> </tbody></table></div>') }); 
 Table 1:- <table id="table66" class="table table-bordered table-hover copySubName"> <input type="button" class="btn green" value="Add New+" id="insert66"></input> <thead> <th>Employee Name</th> </thead> <tbody> <tr> <td> <input type="text" class="form-control EmpName" name="EmpName"> </td> </tr> </tbody> </table> <div class="portlet light portlet-fit box individual individualSalSection"> <input type="button" class="btn green individual" value="Add New+" id="insert17"></input> <div class="portlet-body individual individualSalSectionSub"> <label class="label1 col-md-12 individual labelBoardName" style="display:none"> Enter Board Name </label> <input type="text" class="form-control individual boardName"></input> Table2: <table class="tableboth arrSubjects table table-striped table-hover arrSubjects individual"> <thead> <th>Subject</th> <th> Marks</th> <th> is mandatory</th> </thead> <tbody> <tr> <td> <input type="text" class="form-control EmpName" disabled="true" name="EmpName"> </td> <td> <input type="text" class="form-control years allownumericwithoutdecimal" maxlength="3" name="years"> </td> <td> <input type="checkbox" id="mandatorySub"> </td> </tr> </tbody> </table> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将行数据一一追加到表中? - How to append row data to table one by one? 如何通过Vue将数据从表组件传递到另一个表组件,并使用编辑按钮传递表中的每一行 - how pass data from a table component in vue to another table component passing each row in the table with an edit button 当我勾选同一行复选框时,如何获取另一个表中的表行数据? - How do I get table row data in another table when I tic on same row checkbox? 单击按钮时如何将 append 行添加到表 id =“地址”? - How to append row to table id=“address” on click of button? 我如何 append 删除按钮列到每个表行 - How can I append delete button column to each table row 如何使用在javascript中选中的复选框将表行附加到一个表到另一个表 - How to append table row to one table to another table using checkbox checked in javascript 如果没有子行,如何隐藏表标题行,但是如果单击按钮,如何再次显示标题行 - How to hide table header row if no child rows, but show header row again if button clicked 材料表:如何获取按钮点击时的行数据? (不在行选择上) - Material Table: How to get the row data on Button click? (Not on row selection) 如何在引导模式中的表中附加行 - How to append row in a table in bootstrap modal 如何在嵌套表中添加行 - How to append a row present inside a nested table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM