这个问题在过去曾经出现过几次,但我无法理解它。
这就是我的输出目前的看法:
0 "affiliate_hoover_plugin_options[1][radioName]:mac"
1 "checked:true"
2 "affiliate_hoover_plugin_options[2][radioName]:pc"
3 "checked:false"
4 "affiliate_hoover_plugin...ons[3][radioName]:linux"
5 "checked:false"
这就是我想要的样子:
1: "affiliate_hoover_plugin_options[1][radioName]:mac", "checked:true"
2: "affiliate_hoover_plugin_options[2][radioName]:pc", "checked:false"
3: "affiliate_hoover_plugin...ons[3][radioName]:linux", "checked:false"
这是我的代码的外观:
var newForm = [];
for (var i = 1; i < oldForm.length; i += 1) {
newForm.push(oldForm[i].name + ":" + oldForm[i].value);
if (oldForm[i].type === "radio") {
newForm.push("checked" + ":" + oldForm[i].checked);
}
}
console.log(OnewForm);
现在我要在没有的情况下添加一个额外的for循环,这就是我自己困惑的地方。
我想我只需休息一下
答案 0 :(得分:1)
var newForm = [];
for (var i = 1; i < oldForm.length; i += 1) {
if (oldForm[i].type === "radio") {
newForm.push( [ oldForm[i].name + ":" + oldForm[i].value, "checked:" + oldForm[i].checked ] );
} else {
newForm.push( [ oldForm[i].name + ":" + oldForm[i].value ]);
}
}
答案 1 :(得分:0)
var newForm = [];
for (var i = 0; i < oldForm.length; i++) {
var array = [];
array.push(oldForm[i].name + ":" + oldForm[i].value);
array.push("checked" + ":" + oldForm[i].checked);
newForm.push(array);
}
console.log(newForm);
可能有效