我一直在尝试根据用户输入制作表格,但是,当输入字段退出时,我无法运行单元ID的writeTable函数。我认为这是函数的语法错误,但我无法在线找到解决方案。用户输入表javascript
JAVASCRIPT
<script>
function writeTable(tableID) {
var n = document.getElementById("tableID");
document.getElementById("tableID").innerHTML = n;
}
</script>
HTML
<!-- INPUT TABLE -->
<table>
<tr>
<th>Angle (c)</th>
<th>Voltage - Test 1</th>
<th>Voltage - Test 2</th>
<th>Voltage - Test 3</th>
<th>Voltage - Test 4</th>
</tr>
<tr>
<th> 0 </th>
<th> <input id="00" onblur="writeTable(00)" type="text"> </th>
<th> <input id="10" onblur="writeTable(10)" type="text"> </th>
<th> <input id="20" onblur="writeTable(20)" type="text"> </th>
<th> <input id="30" onblur="writeTable(30)" type="text"> </th>
</tr>
<tr>
<th> π/12 </th>
<th> <input id="01" onblur="writeTable(01)" type="text"> </th>
<th> <input id="11" onblur="writeTable(11)" type="text"> </th>
<th> <input id="21" onblur="writeTable(21)" type="text"> </th>
<th> <input id="31" onblur="writeTable(31)" type="text"> </th>
</tr>
</table>
<!-- DISPLAY TABLE -->
<table>
<tr>
<th>Angle (c)</th>
<th>Voltage - Test 1</th>
<th>Voltage - Test 2</th>
<th>Voltage - Test 3</th>
<th>Voltage - Test 4</th>
</tr>
<tr>
<th> 0 </th>
<th id="00"></th>
<th id="10"></th>
<th id="20"></th>
<th id="30"></th>
</tr>
<tr>
<th> π/12 </th>
<th id="01"> </th>
<th id="11"></th>
<th id="21"></th>
<th id="31"></th>
</tr>
</table>
谢谢,这伟大工程。只是一个简单的问题,是为了使输出ID与输入不同而将id与“t”结合起来? –
对不起,我没有得到你? –
我在问这是什么行 'document.getElementById(“t”+ tableID).innerHTML = n.value;' 但我的问题现在已经回答了prasad –