你能看看,帮助我意识到我会错了这个吗?这里是jsfiddle链接:
http://jsfiddle.net/Hitman666/QcEkj/1/,但也是这里的代码
HTML:
<form action="#" id="gamesForm"> <p> <input id="gName" type="text" class="medium" /> <span class="notification information">Game name</span> </p> <p> <span class="notification information">Enabled:</span> <input id="gEnabled" type="checkBox" /> </p> <br /> <!--Additional data for extra type--> <div id="extraAdditionalData" class="hidden"> <p> <input id="rRacers" type="text" class="medium" /> <span class="notification information">Racers</span> </p> <p> <input id="rVideoSet" type="text" class="medium" /> <span class="notification information">Video set</span> </p> </div> </form> <a href="#" id="saveConfiguration" class="graybuttonBig">Save everything!</a>
JavaScript:
$(document).ready(function(){ $("#saveConfiguration").click(function(){ alert( $("form").serialize() ); }); });
我得到的是一个空字符串。 Thx为您的帮助!
解决方法
你必须给你的表单元素名称!
这是独立于jQuery。每个表单元素必须有一个名称,以便考虑表单提交为successful control:
A successful control is “valid” for submission. Every successful control has its 07001 paired with its 07002 as part of the submitted 07003. A successful control must be defined within a 07004 element and must have a 07001.
jQuery只是忽略那些没有名字的元素(或者,根据它如何获取元素,它可能甚至看不到它们,因为表单本身没有引用它们)。