前言:

   之前是每个input输入框去单个获取值,然后再打包给后台

   有比较快捷的方式是用jq已有方式进行打包,不用再每个输入框去单个获取值,

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<title>Document</title>
</head>
<body>
	<form action="" method="post">
		性别:<input type="text" name="sex" value="男"/><br />
		年龄:<input type="text" name="age" value="18"/><br />
		地址:<input type="text" name="where" value="sichuan"/><br />
		电话:<input type="text" name="phone" value=""/><br />
	</form>
	<button>提交</button>
	<script src="jquery.min.js"></script>
	<script>
		init();
		function init(){
			fun1();
			fun2();
		}
		function fun1(){
			var data=$('form').serializeArray();
			console.log(data);//以数组方式收集
		}
		
		function fun2(){
			var data={};
			$('form').serializeArray().map(function(x){data[x.name]=x.value});
			console.log(data);//已对象方式收集
		}
		
//		提交
		$("body").on("click","button",function(){
		  		init();
		})
	</script>
	
</body>
</html>

收集表单数据——获取打包的表单数据1

比较常用的是已对象方式进行收集

相关文章:

  • 2021-05-19
  • 2022-02-10
  • 2021-06-27
  • 2021-12-31
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
猜你喜欢
  • 2021-06-21
  • 2021-09-28
  • 2021-12-05
  • 2021-06-05
  • 2021-12-31
  • 2021-12-31
  • 2021-12-21
相关资源
相似解决方案