javascript-如何将文本框添加到2d数组
如何将文本框作为输入添加到二维数组?我把文本框作为表单。为每个学生分配座位的最简单方法是什么? 编辑:是否需要将document.getElementById(seat1.innerhtml)放入函数中javascript-如何将文本框添加到2d数组,javascript,arrays,Javascript,Arrays,如何将文本框作为输入添加到二维数组?我把文本框作为表单。为每个学生分配座位的最简单方法是什么? 编辑:是否需要将document.getElementById(seat1.innerhtml)放入函数中 <form id="studentForm"> <input type="text" name="student1" id="myInput1"> <input type="text" name="student2" id="myInput2"> <in
<form id="studentForm">
<input type="text" name="student1" id="myInput1">
<input type="text" name="student2" id="myInput2">
<input type="text" name="student3" id="myInput3"><br>
<input type="text" name="student4" id="myInput4">
<input type="text" name="student5" id="myInput5">
<input type="text" name="student6" id="myInput6"><br>
<input type="text" name="student7" id="myInput7">
<input type="text" name="student8" id="myInput8">
<input type="text" name="student9" id="myInput9"><br>
</form>
<script type="text/javascript">
function myFunction() {
var seat = onearray(3)
seat[1] = onearray(3)
seat[1][1]
seat[1][2]
seat[1][3]
seat[2] = onearray(3)
seat[2][1]
seat[2][2]
seat[2][3]
seat[3] = onearray(3)
seat[3][1]
seat[3][2]
seat[3][3]
}
</script>
<label for="Seat1">Seat 1 </label>
<p id="seat1"></p>
<label for="Seat2">Seat 2 </label>
<p id="seat2"></p>
<label for="Seat3">Seat 3 </label>
<p id="seat3"></p>
<br>
<label for="Seat4">Seat 4 </label>
<p id="seat4"></p>
<label for="Seat5">Seat 5 </label>
<p id="seat5"></p>
<label for="Seat6">Seat 6 </label>
<p id="seat6"></p>
<br>
<label for="Seat7">Seat 7 </label>
<p id="seat7"></p>
<label for="Seat8">Seat 8 </label>
<p id="seat8"></p>
<label for="Seat9">Seat 9 </label>
<p id="seat9"></p>
函数myFunction(){
var seat=onearray(3)
座位[1]=一个阵列(3)
座位[1][1]
座位[1][2]
座位[1][3]
座位[2]=一个阵列(3)
座位[2][1]
座位[2][2]
座位[2][3]
座位[3]=一个阵列(3)
座位[3][1]
座位[3][2]
座位[3][3]
}
座位1
座位2
座位3
座位4
座位5
座位6
座位7
座位8
座位9
尝试使用document.queryselectoral(“input[type=text]”)获取包含所有“text”类型输入的数组。您需要对它们进行迭代
/*选择所有类型为文本的输入,这将返回一个数组*/
var students=document.queryselectoral(“输入[type=text]”);
/*为座位创建一个空多维数组*/
可变座位=[],[];
/*将学生计数器初始化为0*/
var studentCounter=0;
/*迭代seats,大多数时候seats是字符+数字,如:B-24(文件B seat24),但这次是为了将脚本I lef简化为数字,如2-24(文件2 seat24)*/
//24个文件x每个文件10个座位=240个可用座位
对于(var i=0;i这就是我最后所做的
<html>
<head>
<title>Two Dimensional Arrays D</title>
<script type="text/javascript">
function Input()
{
var seat = new Array()
seat[0] = new Array();
seat[0][0] = Form1.txtInput1.value;
seat[0][1] = Form1.txtInput2.value;
seat[0][2] = Form1.txtInput3.value;
seat[1] = new Array();
seat[1][0] = Form1.txtInput4.value;
seat[1][1] = Form1.txtInput5.value;
seat[1][2] = Form1.txtInput6.value;
seat[2] = new Array();
seat[2][0] = Form1.txtInput7.value;
seat[2][1] = Form1.txtInput8.value;
seat[2][2] = Form1.txtInput9.value;
txtLabel1.value = seat[0][0]
txtLabel2.value = seat[0][1]
txtLabel3.value = seat[0][2]
txtLabel4.value = seat[1][0]
txtLabel5.value = seat[1][1]
txtLabel6.value = seat[1][2]
txtLabel7.value = seat[2][0]
txtLabel8.value = seat[2][1]
txtLabel9.value = seat[2][2]
}
</script>
</head>
<form name="Form1">
<table name="InputTable">
<tr>
<td>
Name: <input type="text" name="txtInput1" id="txtInput1">
</td>
<td>
Name: <input type="text" name="txtInput2" id="txtInput2">
</td>
<td>
Name: <input type="text" name="txtInput3" id="txtInput3">
</td>
</tr>
<tr>
<td>
Name: <input type="text" name="txtInput4" id="txtInput4">
</td>
<td>
Name: <input type="text" name="txtInput5" id="txtInput5">
</td>
<td>
Name: <input type="text" name="txtInput6" id="txtInput6">
</td>
</tr>
<tr>
<td>
Name: <input type="text" name="txtInput7" id="txtInput7">
</td>
<td>
Name: <input type="text" name="txtInput8" id="txtInput8">
</td>
<td>
Name: <input type="text" name="txtInput9" id="txtInput9">
</td>
</tr>
</table>
<input type="button" onClick="Input()" value="Submit" name="btnSubmit">
<br />
<br />
<table name="OutputTable">
<tr>
<td>
Seat 1: <input type="text" name="txtLabel1" id="txtLabel1">
</td>
<td>
Seat 2: <input type="text" name="txtLabel2" id="txtLabel2">
</td>
<td>
Seat 3: <input type="text" name="txtLabel3" id="txtLabel3">
</td>
</tr>
<tr>
<td>
Seat 4: <input type="text" name="txtLabel4" id="txtLabel4">
</td>
<td>
Seat 5: <input type="text" name="txtLabel5" id="txtLabel5">
</td>
<td>
Seat 6: <input type="text" name="txtLabel6" id="txtLabel6">
</td>
</tr>
<tr>
<td>
Seat 7: <input type="text" name="txtLabel7" id="txtLabel7">
</td>
<td>
Seat 8: <input type="text" name="txtLabel8" id="txtLabel8">
</td>
<td>
Seat 9: <input type="text" name="txtLabel9" id="txtLabel9">
</td>
</tr>
</table>
<br />
<br />
</form>
</body>
</html>
二维阵列
函数输入()
{
var seat=新数组()
seat[0]=新数组();
席位[0][0]=Form1.txtInput1.value;
席位[0][1]=Form1.txtInput2.value;
席位[0][2]=Form1.txtInput3.value;
seat[1]=新数组();
席位[1][0]=Form1.txtInput4.value;
席位[1][1]=Form1.txtInput5.value;
席位[1][2]=Form1.txtInput6.value;
seat[2]=新数组();
席位[2][0]=Form1.txtInput7.value;
席位[2][1]=Form1.txtInput8.value;
席位[2][2]=Form1.txtInput9.value;
txtLabel1.value=座位[0][0]
txtLabel2.value=座位[0][1]
txtLabel3.value=座位[0][2]
txtLabel4.value=座位[1][0]
txtLabel5.value=座位[1][1]
txtLabel6.value=座位[1][2]
txtLabel7.value=座位[2][0]
txtLabel8.value=座位[2][1]
txtLabel9.value=座位[2][2]
}
姓名:
姓名:
姓名:
姓名:
姓名:
姓名:
姓名:
姓名:
姓名:
座位1:
座位2:
座位3:
座位4:
座位5:
座位6:
座位7:
座位8:
座位9:
你想让计算机自动组织座位和学生,还是让学生自己选择他们想要预定的座位?我想让它像一个老师制定座位计划,能够为每个学生设置座位。我还需要在我遗漏的东西里放一些东西var代码在函数中,或者?我已经修改了脚本,将学生添加到一个座位上,24行10列。对于新的编码,您认为您可以深入解释您所做的吗?我已经在脚本中添加了注释,您将如何获得学生列表?这将来自jSon之类的服务?这只是一个练习代码h没有用。它只是为了让你能把代码放进一个数组中,并能以相同的顺序看到它