您是否尝试为函数命名(此处为 openMain 函数名称) 为了使其更易于理解,我将展示我用于站点的代码。
<form name="myForm" action="mailto:kkatsman@rocfriesepoort.nl?subject=Stickers" enctype="text/plain" method="POST" onsubmit=" return formcheck()">
<table id="formulier">
<tr>
<td>Klas:</td> <td><input type="text" required name="klas" id="klas" onkeyup="vulaan(this)"></td>
</tr><tr>
<td>Examencode:</td> <td><input type="text" required name="examencode" id="examencode" onkeyup="vulaan(this)"></td>
</tr><tr>
<td>Examennaam:</td> <td><input type="text" required name="examennaam" id="examennaam" onkeyup="vulaan(this)"></td>
</tr><tr>
<td>Datum:</td> <td><input type="text" required name="datum" id="datum" onkeyup="vulaan(this)"></td>
<td colspan="2"></td>
<td>Week:</td> <td><input type="text" required name="week" id="week" onkeyup="vulaan(this)"></td>
</tr><tr>
<td>Tijdstip: van</td> <td><input type="text" required name="van" id="van" onkeyup="vulaan(this)"></td> <td>tot</td> <td><input type="text" required name="tot" id="tot" onkeyup="vulaan(this)"></td>
<td>Docent:</td> <td><input type="text" required name="docent" id="docent" onkeyup="vulaan(this)"></td>
</tr>
</table>
因此,当某个文本框中有一个按键时,它指的是函数“vulaan”
现在我的 javascript 文件看起来像:
function vulaan()
{
//voor de klas
var klas = document.getElementById('klas').value;
var klas1 = document.getElementById('klas1').value;
var klas2 = document.getElementById('klas2').value;
document.getElementById('klas1').value = klas;
document.getElementById('klas2').value = klas;
}