【问题标题】:How to map dynamic array of input fields如何映射输入字段的动态数组
【发布时间】:2015-03-18 13:11:39
【问题描述】:

我有一个带有一组输入字段的表单:

<form>
 <div class="row">
     <input type="text" name="product[1]">
     <input type="text" name="qty[1]"> 
 </div>
</form>

我还使用 jquery 的 clone() 函数向 DOM 动态添加新行。

增加索引号的最佳方法是什么?或者有没有更好的方法在提交到 PHP 脚本之前“映射”产品和数量字段?

【问题讨论】:

  • 你可以写product[]qty[],PHP会像数组一样处理你的数据
  • product[] 无索引
  • @FabrizioCalderan,我试过了,但我如何才能确定哪个 qty 值属于哪个产品?
  • 它们都是数组,例如product[42]qty[42] 相关(反之亦然)

标签: javascript php jquery html dom


【解决方案1】:

试试这个:

<form>
 <div class="row">
     <input type="text" name="product[]">
     <input type="text" name="qty[]"> 
 </div>
   <div class="row">
     <input type="text" name="product[]">
     <input type="text" name="qty[]"> 
 </div>
</form>

【讨论】:

    猜你喜欢
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 2018-03-24
    相关资源
    最近更新 更多