[英]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:- 我已经开发了一种表格,其中使用一些表格来获取数据,其中一些与这些表格有关的关键点是:
"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按钮添加的所有其他表中的行数将会增加。
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:- 但是我面临的一些问题是:
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按钮将其添加。)
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 -
我还添加了每种方法来在新表中添加员工姓名-
$(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.