HTML表单作为数组与键 - 值对

时间:2014-07-12 22:05:46

标签: javascript html arrays forms

是否可以在纯HTML中创建表单,以便在传递时,结果是数组,但'name'成为索引'key',值变为索引'value'?

例如,假设我的表单有多个attributes。第一个attributecolor,第二个是abbv,第三个是cost

所以我想得到以下形式的数组:

attributes: [
    {
        key : 'color',
        value: 'the color the user picks'
    },
    {
        key : 'abbv',
        value: 'the abbreviation the user types'
    },
    {
        key : 'cost',
        value: 'the cost the user assigns'
    }    
]

我想知道纯HTML是否可行。我知道我可以在Javascript中执行此操作。

1 个答案:

答案 0 :(得分:1)

您要求的是HTML表单提交的application/json编码类型。

目前尚未为HTML指定此类型,从版本5开始,specifies three encoding types

  1. application/x-www-form-urlencoded
  2. multipart/form-data
  3. text/plain
  4. 当然,如果它受到支持,则无法保证它会以您指定的格式序列化数据。