举例:form表单中有如下几个input<input type="text" name="brand" value="XX品牌"><input type="text" name="model" value="XX型号"><input type="text" name="upload_pic" value="111"><input type="text" name="upload_pic" value="222"><input type="text" name="upload_pic" value="333">期望让name相同的几个upload_pic变成如下样子{ "brand": "XX品牌", "model": "XX型号", "upload_pic": [ "111", "222", "333" ]}请问应该怎么做?
1 回答
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
建议你加个class
<input type="text" class="upload_pic" name="upload_pic" value="333">
js
var upload_pic = new Array();
var len = document.querySelectorAll(".upload_pic").length;
for(var i = 0;i<len;i++){
var v =document.querySelectorAll(".upload_pic")[i].value();
upload_pic.push(v);
}
这样更简单更实用
添加回答
举报
0/150
提交
取消