<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
姓名:<input type="text"><br>
年龄:<input type="text"><br>
性别:<input type="text"><br>
学号:<input type="text"><br>
<button οnclick="func()">添加</button>
<div></div>
</body>
<script>
var inp=document.getElementsByTagName("input");
var di=document.getElementsByTagName("div")[0];
var sz=[];
function func(){
var dx={
xm:inp[0].value,
nl:inp[1].value,
xb:inp[2].value,
xh:inp[3].value
}
sz.push(dx);
var str=""
for(let i=0;i<sz.length;i++){
str+=sz[i].xm+sz[i].nl+sz[i].xb+sz[i].xh
}
di.innerHTML=str
}
</script>
</html>