[問題] JQuery form serialization
想請問為何 var formData = $('#testform').serialize(); 序列化出來的資料是空的?
感謝大家
<!DOCTYPE html>
<html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="Scripts/jquery-2.1.0.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btnSerialize').on('click', Serialize);
$('#btnDecode').on('click', Decode);
});
function Serialize() {
var formData = $('#testform').serialize();
$('#beforeDecode').val(formData.toString());
}
function Decode() {
var encodeData = $('#beforeDecode').val();
var decodeData = decodeURIComponent(encodeData);
$('#afterDecode').val(decodeData.toString());
}
</script>
</head>
<body>
<form id="testform" >
<input type="text" id="myName" value="myName"/>
<input type="text" id="myEmail" value="myEmail"/>
</form>
<label for="beforeDecode"> The data of test form is: </label>
<input type="text" id="beforeDecode" />
<label for="afterDecode"> The data of test form is: </label>
<input type="text" id="afterDecode" />
<button id="btnSerialize">Serialize</button>
<button id="btnDecode">Decode</button>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.165.254.39
→
03/13 04:41, , 1F
03/13 04:41, 1F
→
03/13 04:51, , 2F
03/13 04:51, 2F
→
03/13 04:54, , 3F
03/13 04:54, 3F
→
03/13 05:11, , 4F
03/13 05:11, 4F
→
03/13 13:37, , 5F
03/13 13:37, 5F
推
03/13 13:57, , 6F
03/13 13:57, 6F
→
03/13 13:57, , 7F
03/13 13:57, 7F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):