想请问为何 var formData = $('#testform').serialize(); 序列化出来的资料是空的?
感谢大家
<!DOCTYPE html>
<html xmlns="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>