<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
window.onload = function () {
var inputs = document.getElementsByTagName('input');
for(var i=0; i<inputs.length; i++){
var ipt = inputs[i];
if(ipt.type === 'text'){
ipt.value = i;
}
}
var txt = document.getElementById('txt');
txt.onclick = function () {
var array = [];
for(var i=0; i<inputs.length; i++){
var ipt = inputs[i];
if(ipt.type === 'text'){
array.push(ipt.value);
}
}
console.log(array.join());
}
}
</script>
</head>
<body>
<input type="text" ><br>
<input type="text" ><br>
<input type="text" ><br>
<input type="text" ><br>
<input type="text" ><br>
<input type="button" id="txt" value="获取文本框的值">
</body>
</html>