zl程序教程

您现在的位置是:首页 >  后端

当前栏目

jQueryajaxserialize()方法使用示例

方法 使用 示例
2023-06-13 09:15:30 时间

.serialize()方法创建以标准URL编码表示的文本字符串。它的操作对象是代表表单元素集合的jQuery对象。

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<scriptsrc="Scripts/jquery-1.4.1.js"type="text/javascript"></script>
<scripttype="text/jscript">
//$(function(){
//alert($("form").serialize());
//})

functionbtnClick(){
alert($("form").serialize());
}
</script>
</head>
<body>
<form>
<div><inputtype="text"name="a"value="1"id="a"/></div>
<div><inputtype="text"name="b"value="2"id="b"/></div>
<div><inputtype="hidden"name="c"value="3"id="c"/></div>
<div>
<textareaname="d"rows="8"cols="40">4</textarea>
</div>
<div><selectname="e">
<optionvalue="5"selected="selected">5</option>
<optionvalue="6">6</option>
<optionvalue="7">7</option>
</select></div>
<div>
<inputtype="checkbox"name="f"value="8"id="f"/>
</div>
<div>
<inputtype="button"name="g"value="提交"id="g"onclick="btnClick()"/>
</div>
</form>

</body>
</html><spanstyle="font-size:18px;color:#ff0000;">
</span>

点击提交:

输出标准的查询字符串:a=1&b=2&c=3&d=4&e=5

如果将复选框也选上的话输出的就是:a=1&b=2&c=3&d=4&e=5&f=8