jQuery序列化

Posted JohnRey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery序列化相关的知识,希望对你有一定的参考价值。

  • html代码如下:
    <form>
        用户名:<input type="text" name="user"/>
        邮件:<input type="text" name="email"/>
        <input type="radio" name="sex" value="男"/><input type="radio" name="sex" value="女"/><input type="button" value="提交"/>
    </form>
    <div id="box"></div>

 

  • jQuery代码如下
    $("form input[type=button]").click(function () {
        $.ajax({
            type: "POST",
            url: "/user/",
            data:$("form").serialize(),//序列化form表单数据
            success:function (response,status,xhr) {
                $("#box").html(response);
            }
        });
    });

 

    $("form input[name=sex]").click(function(){
       $("#box").html(decodeURIComponent($(this).serialize()));//序列化radio数据,并对其解码
    });

 

以上是关于jQuery序列化的主要内容,如果未能解决你的问题,请参考以下文章

markdown 在WordPress中使用jQuery代码片段

使用 NodeJS 和 JSDOM/jQuery 从代码片段构建 PHP 页面

很实用的JQuery代码片段(转)

几个有用的JavaScript/jQuery代码片段(转)

几个非常实用的JQuery代码片段

高效Web开发的10个jQuery代码片段