对serialize数组的追加解决方法
2014-03-20 00:00:00 by 【6yang】,
577
visits,
收藏 |
返回
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>对serialize数组的追加解决方法</title>
<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form_id">
<input type="text" name="name" value="jack" />
<input type="text" name="age" value="12" />
<input type="checkbox" name="courses[]" value="语文" checked />
<input type="checkbox" name="courses[]" value="数学" checked/>
<input type="text" name="education" value="master" />
<input type="button" value="submit" />
</form>
<script>
$(function(){
var $form_id = $('#form_id');
//serialize 作用
var odata = $form_id.serialize() + '&email=test@163.com';
console.log(odata);
$.post('test.php', odata, function(res){
console.log(res);
}, 'json');
//serializeArray 作用
var odata = $form_id.serializeArray();
$.each(odata, function(i, field){
console.log(field.name + ':' + field.value);
});
})
</script>
</body>
</html>
share