Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 一个模式中有多个动态表单,但如何提交?_Jquery_Forms - Fatal编程技术网

Jquery 一个模式中有多个动态表单,但如何提交?

Jquery 一个模式中有多个动态表单,但如何提交?,jquery,forms,Jquery,Forms,我完全被这件事缠住了。我真的不知道该怎么做了,所以如果有人愿意帮助我,举一些例子或者给我指出一些非常有用的方向 情况就是这样: 我有一个模态(eric martins SimpleModel)窗口,其中一些表单是用一些JSON细节生成的。这是通过以下代码完成的: $.each(data.product.variants, function(index, variant){ contentHtml = contentHtml +

我完全被这件事缠住了。我真的不知道该怎么做了,所以如果有人愿意帮助我,举一些例子或者给我指出一些非常有用的方向

情况就是这样:

我有一个模态(eric martins SimpleModel)窗口,其中一些表单是用一些JSON细节生成的。这是通过以下代码完成的:

         $.each(data.product.variants, function(index, variant){     

          contentHtml = contentHtml +
            '<div id="form">' +
            '<form class="formProduct" id="formProduct'+variant.id+'" action="#" >' +
            '<div class="variants">' +
            '<div class="pop_variantTitle"><label><input type="hidden" id="variantId" name="'+ variant.id + '" value="' + variant.id + '" />' + variant.title + '</label></div>' +
            '<div class="pop_variantQuantity"><label">{{ 'Quantity' | t }}: <input type="text" name="quantity" id="formProductQuantity" value="1" /></label></div>' +
            '<div class="pop_variantAdd"><a class="button green submit" href="#"><span>{{ 'Add to cart' | t }}</span></a></div>' + //
            '</div>' +
            '</form>' +
            '</div>';
         });     
        $('.formProductContent').html(contentHtml);
      });         
    }})
  return false;
  })

  $().ready(function(){

var form = $('form').attr('id');

$(form).submit(function() { return false; });

$(".submit").live("click", function(){

var quantity = $("#formProductQuantity").val();
var variant = $("#variantId").val();

$(".submit").replaceWith("send...");

$.ajax({
type: 'POST',
url: '{{ 'cart/add/' }}'+variant+'/?quantity='+quantity+'',
data: $(form).serialize(), //"formProduct"
success: function(data) {
/*if(data == "true") {
$(form).fadeOut("fast", function(){
$(this).before("<p><strong>Success! Your feedback has been sent, thanks :)</strong></p>");
setTimeout("$.fancybox.close()", 1000);
});
}*/
 }
});
});
});
$.each(data.product.variants,function(index,variant){
contentHtml=contentHtml+
'' +
'' +
'' +
''+变体.标题+''+
“改变

.class选择器返回所有类,但您需要处理它们。对于您的代码,它将仅对找到的第一个.class有效。

更改

$(".submit").live("click", function(){
    //code
}


.class selector返回所有类,但您需要处理它们。对于您的代码,它将仅与first.class found一起工作。

Thx接受您的建议,但它似乎不起作用。现在没有提交任何内容。您说我的脚本是如何构建的,这是唯一的方法……也许您有更好/更简单的方法用表单编写此类模式?+1代表y我们的帮助谢谢你的建议,但它似乎不起作用。现在没有提交任何内容。你说我的脚本是如何构建的,这是唯一的方法…也许你有更好/更简单的方法用表单编写此类模式?+1谢谢你的帮助
$(".submit").each(function(){
    $(this).live("click", function(){
        //code
    }
});