我有一个带有选中复选框的表单。它的序列化不会返回那些选中的复选框。这是我用来执行序列化的 jQuery 代码。
$('form.subscribe').serialize()
上述序列化返回
email=
这是标记:
<form class="subscribe">
<div class="body">
<div class="email input">
<input name="email" placeholder="your email address" />
</div>
<div class="expandable">
<div class="fieldLabel emphasis">I am a:</div>
<div class="checkbox">
<input id="isDeveloper" type="checkbox" />
<label for="isDeveloper">Developler<label>
</div>
<div class="checkbox">
<input id="isDesigner" type="checkbox" />
<label for="isDesigner">Designer</label>
</div>
<div class="checkbox">
<input id="isHR" type="checkbox" />
<label for="isHR">Talent Coordinator</label>
</div>
<div class="checkbox">
<input id="isPM" type="checkbox" />
<label for="isPM">Project Manager</label>
</div>
<div class="fieldLabel emphasis">Email me about:</div>
<div class="checkbox">
<input id="wantsCollab" type="checkbox" checked="checked"/>
<label for="wantsCollab">Collaboration</label>
</div>
<div class="checkbox">
<input id="wantsBlog" type="checkbox" checked="checked" />
<label for "wantsBlog">Blog Posts</label>
</div>
</div>
<div class="button">
<input class="emphasis" type="submit" value="subscribe">
</div>
</div>
</form>
如您所见,有 1 个文本输入和 6 个复选框。选中其中 2 个复选框,但序列化中仅返回文本输入。