是否可以在纯HTML中创建表单,以便在传递时,结果是数组,但'name'成为索引'key',值变为索引'value'?
例如,假设我的表单有多个attributes
。第一个attribute
是color
,第二个是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中执行此操作。
答案 0 :(得分:1)
您要求的是HTML表单提交的application/json
编码类型。
目前尚未为HTML指定此类型,从版本5开始,specifies three encoding types:
application/x-www-form-urlencoded
multipart/form-data
text/plain
当然,如果它受到支持,则无法保证它会以您指定的格式序列化数据。