序列化表单在jQuery中不起作用 [英] Serialize form not working in jQuery

查看:187
本文介绍了序列化表单在jQuery中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您看看并帮助我意识到我在哪里出问题了?这是jsfiddle链接: http://jsfiddle.net/Hitman666/QcEkj/1/但这也是代码

Can you please take a look and help me realize where am I going wrong with this? Here is the jsfiddle link: http://jsfiddle.net/Hitman666/QcEkj/1/ but also here is that code

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:

JavaScript:

$(document).ready(function(){
    $("#saveConfiguration").click(function(){
        alert( $("form").serialize() );   
    });
});  

我得到的只是一个空字符串.

All I'm getting is an empty string.

推荐答案

您必须给表单元素name s!

You have to give your form elements names!

这独立于jQuery.每个表单元素都必须有一个name才能被考虑为 成功控制 :

This is independent of jQuery. Every form element must have a name to be considered for form submission as successful control:

成功提交的控件对提交是有效的".每个成功的控件都有其控件名称和其当前值作为提交的 FORM 中定义成功的控件元素,并且必须具有控件名称.

A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.

jQuery只是忽略那些没有名称的元素(或者,取决于它如何获取元素,它可能甚至看不到它们,因为表单本身没有对它们的引用).

jQuery just ignores those elements that don't have a name (or, depending on how it gets the elements, it might not even see them as the form itself has no reference to them).

这篇关于序列化表单在jQuery中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆