<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>序列化表单</title>
<script type="text/javascript" src="js部分/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
var serializeObject = function(form){
var obj = {};
$.each(form.serializeArray(), function(index){
if(obj[this['name']]){
obj[this['name']] = obj[this['name']] + "," + this['value'];
}else{
obj[this['name']] = this['value'];
}
});
return obj;
}
$(function(){
$("#mybutton").click(function(){
var obj = serializeObject($("#myform"));
alert(obj);
console.info(obj);
});
});
</script>
</head>
<body>
<form id="myform">
姓名:<input type="text" name="name"/><br/>
年龄:<input type="text" name="age"/><br/>
学历:<input type="text" name="education"/><br/>
</form>
<br/><input type="button" value="序列化表单" id="mybutton"/>
</body>
</html>