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数据,并对其解码 });