我一直在嘗試根據用戶輸入製作表格,但是,當輸入字段退出時,我無法運行單元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 –