2016-01-22 39 views
0

数量元件的结构: /for循环/ /内内for循环/如何将jQuery事件值插入数组?

正如所看到的上面,输入[名称=数量]是伴随着输入[名称= qty2 []]。我所需要做的就是将值输入到[name = qty]中,该值必须存储在其输入对[name = qty2 []]中。因为当提交这个表单时,我需要qty的所有值,这就是为什么我需要qty2 []一个数组来保存它们。

编辑:

此我想要做什么,但总额不起来总数量和总金额价值。

声明数组$。每个循环

var collectQty = []; 

内。每$循环

collectQty.push(product_quantity); 

外$。每个循环

var qty2 = collectQty.join(", "); 
     $('input[id^='+param+'_qty2]').val().push(qty2); 

这说明如下。注:较宽的文本框是qty2 []

enter image description here

+0

这真的很难理解你在这里之后。你能澄清吗? – billynoah

+0

@billynoah,我需要将输入[name = qty]的值存储到输入[name = qty2 []中,因为它们被键入。 – 112233

+0

@billynoah,我编辑了我的帖子,看看你现在是否可以更好地理解 – 112233

回答

1

,我觉得你可以做一些简单的像这样:

<td class='qty_"+data[i].id+"'> 
    <input type='text' name='qty' style='width:50px;height:20px;margin:10px auto;' value='' onchange='$(this).next(\"input\").val(this.value); subTotal2(\""+data[i].id+"\")'> 
    <input type='hidden' id = '"+data[i].id+"_qty2[]' name='qty2[]' value=''> 

可能会更好地把这样的东西在<script>块,但:

<script type="text/javascript"> 
    $('input[name=qty]').on('input', function() { 
     $(this).next('input').val(this.value); 
    }); 
</script> 
+0

它采取最新所有qty2 []的值 – 112233