我想使用 SerializeJSON 序列化我的表单,我有一个 div,里面有多个选项卡,每个选项卡都有多个表单。我如何在 div 内循环以获取选项卡,在每个选项卡内我想获取表单,以便我可以对其进行序列化,然后根据所需的结构将其放入数组中。
<div class="clamp-content">
<div id="tab1">
<form id="materialinfo">
<input name="plateMaterial">
<input name="plateMaxAllowableStressDesignTemperature">
</form>
<form id="defectparam">
<input name="Def_L">
<input name="DefL_2">
</form>
</div>
<div id="tab2">
<form id="materialinfo">
<input name="plateMaterial">
<input name="plateMaxAllowableStressDesignTemperature">
</form>
<form id="defectparam">
<input name="Def_L">
<input name="DefL_2">
</form>
</div>
</div>
我想要的欲望结构是这样的:
CaseInfo:
0: {{plateMaterial:"plateMaxAllowableStressDesignTemperature"}, {Def_L: "", DefL_2: ""}
1: {{plateMaterial:"plateMaxAllowableStressDesignTemperature"}, {Def_L: "", DefL_2: ""}
我尝试过这样的事情:
var designParameter = [];
var form = {};
function save() {
$('.clamp-content').children().each(function () {
$(this).find('form').each(function () {
form = $(this).serializeJSON();
console.log(form)
});
});
}
但是当我控制台记录表单时,我得到的是:
{plateMaterial: "", plateMaxAllowableStressDesignTemperature: "", plateMaxAllowableStressOperatingTemperature: "", plateThickness: "", boltMaterial: "", …}
{Def_L: "", DefL_2: "", Def_D: "", DefD_3: "", DefD_2: "", …}
{plateMaterial2: "", plateMaxAllowableStressDesignTemperature2: "", plateMaxAllowableStressOperatingTemperature2: "", plateThickness2: "", boltMaterial2: "", …}
{Def_L2: "", DefL_22: "", Def_D2: "", DefD_32: "", DefD_22: "", …}
任何帮助将不胜感激。谢谢你 :)