Php 动态表单添加/删除字段
我尝试创建一个可以动态添加/删除输入的表单。 我可以通过单击按钮创建新行,但当我将值传递到其他页面时,我的输入似乎没有被收集 这是密码Php 动态表单添加/删除字段,php,jquery,forms,dynamic,Php,Jquery,Forms,Dynamic,我尝试创建一个可以动态添加/删除输入的表单。 我可以通过单击按钮创建新行,但当我将值传递到其他页面时,我的输入似乎没有被收集 这是密码 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script> $(document).ready(function(e){ //var
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$(document).ready(function(e){
//var
var x = 1;
//add
$("#add").click(function(e){
x++;
var mark = '<tr><td width="200" height="30" align="center">'+x+'</td><td width="200" height="30" align="center"><input type="text" name="item_name[]" /></td><td width="200" height="30" align="center"><input type="text" name="item_fact[]" /></td><td width="200" height="30" align="center"><input type="text" name="item_desc[]" /></td><td width="200" height="30" align="center"><input type="text" name="item_amount[]"/></td><td width="200" height="30" align="center"><input type="text" name="item_price[]" /></td><td width="200" height="30" align="center"><a herf="#" id="remove" class="button">X</a></td></tr>';
$("#dynamic_field").append(mark);
});
//remove
$("#dynamic_field").on('click','#remove', function(e){
$(this).closest('tr').remove();
x--;
});
});
</script>
$(文档).ready(函数(e){
var x=1;//用于行计数
//添加更多按钮单击
$(“#添加”)。单击(函数(e){
x++;
//添加到“添加更多”上的行html单击var标记=''+x+'x'
$(“#mt tr:last”).after(mark);//在上一个现有tr之后添加行
});
//X单击的代码
$(“#mt”)。在('click','#remove',函数(e)上{
//删除当前行
$(this).closest('tr').remove();
x--;
});
});
1.
$(文档).ready(函数(e){
var x=1;//用于行计数
//添加更多按钮单击
$(“#添加”)。单击(函数(e){
x++;
//添加到“添加更多”上的行html单击var标记=''+x+'x'
$(“#mt tr:last”).after(mark);//在上一个现有tr之后添加行
});
//X单击的代码
$(“#mt”)。在('click','#remove',函数(e)上{
//删除当前行
$(this).closest('tr').remove();
x--;
});
});
1.
如何将值传递到另一个页面?我假设您正在执行ajax调用以将值传递到“另一个页面”。您还必须为ajax添加代码。我将以sumbit形式通过post方法传递值。我需要编写代码从ajax传递值?我想只要加上相同的输入名就可以了。我可以查看任何示例吗?如何将值传递到另一个页面?我假设您正在执行ajax调用以将值传递到“另一个页面”。您还必须为ajax添加代码。我将以sumbit形式通过post方法传递值。我需要编写代码从ajax传递值?我想只要加上相同的输入名就可以了。当用户点击添加更多Button$(“#mt tr:last”)。之后(标记);表示在最后一个现有表行(tr)后添加一行$(“#mt”).on('click','#remove',函数(e){$(this).closest('tr').remove();x--});删除单击的当前行。如果有任何查询,请让我知道。请在用户单击添加更多Button$(“#mt tr:last”)。之后(标记)将此类解释添加到代码中,而不是添加到注释部分;表示在最后一个现有表行(tr)后添加一行$(“#mt”).on('click','#remove',函数(e){$(this).closest('tr').remove();x--});删除单击的当前行。如果有任何查询,请告诉我。请将此类解释添加到代码中,而不是添加到注释部分
<tr id="container">
<td width="200" height="30" align="center">1</td>
<td width="200" height="30" align="center"><input type="text" name="item_name[]"/></td>
<td width="200" height="30" align="center"><input type="text" name="item_fact[]"/></td>
<td width="200" height="30" align="center"><input type="text" name="item_desc[]"/></td>
<td width="200" height="30" align="center"><input type="text" name="item_amount[]"/></td>
<td width="200" height="30" align="center"><input type="text" name="item_price[]"/></td>
<td width="200" height="30" align="center"><a herf="#" id="add" class="button">Add more</a></td>
</tr>
item_name => Array ( [0] =>test 1)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$(document).ready(function(e){
var x = 1; //for row count
//add more button click
$("#add").click(function(e){
x++;
$("#mt tr:last").after(mark); //add the row after the last existing tr
});
//code for X click
$("#mt").on('click','#remove', function(e){
//remove the current row
$(this).closest('tr').remove();
x--;
});
});
</script>
<table id="mt">
<tr id="container">
<td width="200" height="30" align="center">1</td>
<td width="200" height="30" align="center"><input type="text" name="item_name[]"/></td>
<td width="200" height="30" align="center"><input type="text" name="item_fact[]"/></td>
<td width="200" height="30" align="center"><input type="text" name="item_desc[]"/></td>
<td width="200" height="30" align="center"><input type="text" name="item_amount[]"/></td>
<td width="200" height="30" align="center"><input type="text" name="item_price[]"/></td>
<td width="200" height="30" align="center"><a href="javascript:void(0)" id="add" class="button">Add more</a></td>
</tr>
</table>