jQuery 的.serialize()

<%@ 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" οnclick="test()">測試</button>
</form>
</body>
</html>
可見,被選中的checkbox,和radio纔會有key=value值,每一個checkbox都會生成一個key=value對,即使他們的名字是相同的。
發佈了34 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章