【发布时间】:2019-04-19 09:28:04
【问题描述】:
我尝试创建一个可以动态添加/删除输入的表单。 我可以通过单击一个按钮来创建一个新行,但是当我将一个值传递给另一个页面时,我的输入似乎没有被收集。
这是代码
<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>
这是html代码
<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>
当print_r 的值它传递输入只是html 输入。
item_name => Array ( [0] =>test 1)
【问题讨论】:
-
如何将值传递给其他页面?
-
我假设您正在执行 ajax 调用以将值传递给“其他页面”。您还必须为 ajax 添加代码。
-
我通过 sumbit 形式通过 post 方法传递值。我需要编码以从 ajax 传递值?我想只需附加相同的输入名称即可。有什么样品可以看吗?