php 动态增加输入行,添加动态输入的php&jquery

我使用jquery在我的页面上添加动态输入。我最初只想显示一个输入,然后单击一个按钮可以添加更多输入。

这按预期工作。

然后我使用php来捕获

$_POST

输入值并将其发送到外部脚本。这同样有效,但是我总是在数组中收到一个额外的项目,而且它是空的。

我想这是因为我隐藏了

“我的HTML”中的字段,在生成新输入时显示该字段?

我的代码如下;

HTML

// unnecessary code removed

JQuery

$(document).ready(function() {

//here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class.

$(".add-more").click(function() {

var html = $(".copy-fields").html();

$(".after-add-more").after(html);

});

//here it will remove the current value of the remove button which has been pressed

$("body").on("click", ".remove", function() {

$(this).parents(".control-group").remove();

});

});

PHP

// unnecessary code removed

$field_values_array = $_POST['addmore'];

?>

在不生成额外输入的情况下,我输入

1111111

输入框并提交。一

print_r($_POST)

生产;

[addmore] => Array

(

[0] => 1111111

[1] =>

)

感谢您的帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值