jQuery 的.serialize()

来源:互联网 发布:windows 错误恢复 编辑:程序博客网 时间:2024/05/16 13:47
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script src="/RedseaPlatform/skins/library/jquery/jquery-1.11.1.min.js"type="text/javascript"></script><script type="text/javascript">function test(){console.log($("#testForm").serialize());alert($("#testForm").serialize());}</script></head><body><form id="testForm"><input type="checkbox" name="field1" value="1" checked /><input type="text" name="field2" value="1" /><input type="radio" name="field3" value="0" /><input type="radio" name="field3" value="1" /><button type="button" onclick="test()">测试</button></form></body></html>
可见,被选中的checkbox,和radio才会有key=value值,每一个checkbox都会生成一个key=value对,即使他们的名字是相同的。
0 0