是否可以在纯HTML中创建一个表单,以便在传递时,结果是数组,但'name'成为索引'key',value成为索引'value'?
例如,假设我的表单有多个属性
。第一个 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 执行此操作。
最佳答案
您要求的是用于 HTML 表单提交的 application/json
编码类型。
当前未为 HTML 指定此类型,从版本 5 开始,specifies three encoding types :
application/x-www-form-urlencoded
多部分/表单数据
text/plain
当然,如果支持它,也不能保证它会以您指定的格式序列化数据。
关于javascript - HTML 表单作为带有键值对的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24717741/