【问题标题】:POST form dynamically generated inputsPOST 表单动态生成的输入
【发布时间】:2014-12-28 03:33:25
【问题描述】:

我有一个表单,在单击调用附加函数的按钮时动态添加输入。提交表单后,我只能访问在页面加载时创建的输入。我使用以下调试代码仔细检查了这一事实。警报确实不显示动态生成的 ID。

$('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--;
    })
});

jsfiddle.net/52VtD/9763 非常感谢任何帮助

【问题讨论】:

  • 你的开发者控制台打开了吗?看到任何错误?有什么事吗?
  • 检查您的报价。使用" 而不是
  • jsfiddle.net/52VtD/9763 窗体在模态窗口中,单击小方块将其打开。按钮图像未呈现。
  • @sectus 我更改了它们,现在序列化调试代码显示了这些东西,但 php 表单仍然无法通过帖子看到它们

标签: javascript php jquery forms submit


【解决方案1】:

1.我的一些结束引号是用我的法语键盘写的,因此是错误的。 2.我把ID里面的[]去掉了。

【讨论】:

    猜你喜欢
    • 2013-10-04
    • 2021-09-06
    • 2012-01-02
    • 2016-06-14
    • 2015-06-16
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 2013-06-17
    相关资源
    最近更新 更多