通过serialize() 方法,可以对表单内容进行序列化。以键值对的方式进行呈现。

序列化后格式为:

​name1=name1值&name2=name2值&name3=name3值....​

举例:

<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
</head>
<body>
<form action="http://localhost:2000/" method="post">
<label>
时间:
<input type="text" name="l_name">
</label>
<br>
<label>
地点:
<input type="text" name="l_address">
</label>
<br>
<label>
人物:
<input type="text" name="l_person">
</label>
<br>
<input id="btn_sub" type="button" value="提交">
</form>
<script src="node_modules/jquery/dist/jquery.js"></script>
<script>
$('#btn_sub').on('click', function () {
var $form = $('form');
console.log($form.serialize());
return false;
});
</script>
</body>
</html>

点击提交后输出

jQuery:ajax中form表单serialize()序列化方法_html