Javascript POST表单动态生成的输入
我有一个表单,在点击调用append函数的按钮时,动态添加输入。提交表单后,我只能访问页面加载时创建的输入。我使用以下调试代码仔细检查了这个事实。该警报确实不会显示动态生成的IDJavascript POST表单动态生成的输入,javascript,php,jquery,forms,submit,Javascript,Php,Jquery,Forms,Submit,我有一个表单,在点击调用append函数的按钮时,动态添加输入。提交表单后,我只能访问页面加载时创建的输入。我使用以下调试代码仔细检查了这个事实。该警报确实不会显示动态生成的ID $('form').submit(function() { alert($(this).serialize()); return false; }); 脚本如下: $(document).ready(function() { var max_fields = 10; //maxi
$('form').submit(function() {
alert($(this).serialize());
return false;
});
脚本如下:
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 0; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++;
var printCounter = document.getElementById("product_counter");
printCounter.value = x;
//increment
$(wrapper).append('<div>' +
'<div class="input-group">' +
'<span class="input-group-addon">Nom</span>'+
'<input id="vch_invoice_item['+x+']” name="vch_invoice_item['+x+']” value="" type="text" class="form-control" placeholder="">'+
'</div>'+
'<div class="input-group">'+
'<span class="input-group-addon">Description</span>'+
'<input id="vch_invoice_description['+x+']” name="vch_invoice_description['+x+']" value="" type="text" class="form-control" placeholder="">'+
'</div>'+
'<div class="input-group">'+
'<span class="input-group-addon">Prix à l’unité</span>'+
'<input onclick="bindPriceMask(this)" onfocus="bindPriceMask(this)" id="vch_invoice_unitcost['+x+']” name="vch_invoice_unitcost['+x+']” value="" type="text" class="unit form-control" placeholder="">'+
'</div>'+
'<div class="input-group">'+
'<span class="input-group-addon">Quantité</span>'+
'<input onclick="bindQtyMask(this)" onfocus="bindQtyMask(this)" id="vch_invoice_quantity['+x+']” name="vch_invoice_quantity['+x+']” value="" type="text" class="qty form-control" placeholder="">'+
'</div>'+
'<div class="input-group">'+
'<span class="input-group-addon">Taxe Fédérale</span>'+
'<input onclick="bindTaxMask(this)" onfocus="bindTaxMask(this)" id="vch_invoice_fedTax['+x+']” name="vch_invoice_fedTax['+x+']” value="" type="text" class="taxf form-control" placeholder="">'+
'</div>'+
'<div class="input-group">'+
'<span class="input-group-addon">Taxe Provinciale</span>'+
'<input onclick="bindTaxMask(this)" onfocus="bindTaxMask(this)" id="vch_invoice_provTax['+x+']” name="vch_invoice_provTax['+x+']” value="" type="text" class="taxp form-control" placeholder="">'+
'</div>'+
'<a href="#" class="remove_field">Supprimer</a><br><br><br>'+
'</div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
$(文档).ready(函数(){
var max_fields=10;//允许的最大输入框数
var wrapper=$(“.input_fields_wrapp”);//字段包装器
var add_button=$(“.add_字段_button”);//添加按钮ID
var x=0;//初始文本框计数
$(添加按钮)。单击(函数(e){//在添加输入按钮上单击
e、 预防默认值();
如果(x 我的一些结束语是用法语键盘写的,因此是错误的。
2.我取出ID中的[]。您的开发人员控制台打开了吗?是否看到任何错误?是否有任何问题?请检查您的报价。使用“
而不是”
表单在一个模式窗口中,单击小正方形打开它。按钮图像没有呈现。@sectus我更改了它们,现在序列化调试代码显示了内容,但php表单仍然无法通过post看到它们