用户类型表javascript

用户类型表javascript,javascript,html,Javascript,Html,我一直在尝试根据用户输入创建一个表,但是,当输入字段退出时,我无法运行cell id的writeTable函数。我假设这是函数的语法错误,但我无法在线找到解决方案 JAVASCRIPT <script> function writeTable(tableID) { var n = document.getElementById("tableID"); document.getElementById("tableID").innerHTML =

我一直在尝试根据用户输入创建一个表,但是,当输入字段退出时,我无法运行cell id的writeTable函数。我假设这是函数的语法错误,但我无法在线找到解决方案

JAVASCRIPT

<script>
    function writeTable(tableID) {
        var n = document.getElementById("tableID");
        document.getElementById("tableID").innerHTML = n;
    }
</script>

函数可写(tableID){
var n=document.getElementById(“tableID”);
document.getElementById(“tableID”).innerHTML=n;
}
HTML


角度(c)
电压-测试1
电压-测试2
电压-测试3
电压-测试4
0
π/12 
角度(c)
电压-测试1
电压-测试2
电压-测试3
电压-测试4
0
π/12 

试试这个。你可以更改你的html
onclick=writeTable('targetlementid',this)
。并且不要对
输入和
td
都使用一些id。因为id是唯一的。所以要区分
td
和输入id。就像在
td id=“t00”之前添加
t
函数writeTable(tableID,that){
document.getElementById('t'+tableID).innerHTML=that.value;
}

角度(c)
电压-测试1
电压-测试2
电压-测试3
电压-测试4
0
π/12 
角度(c)
电压-测试1
电压-测试2
电压-测试3
电压-测试4
0
π/12 

以下是您的解决方案:

    <!-- 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="0" 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="1" 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="t0"></th>
            <th id="t10"></th>
            <th id="t20"></th>
            <th id="t30"></th>
        </tr>
        <tr>
            <th> 12 </th>
            <th id="t1"> </th>
            <th id="t11"></th>
            <th id="t21"></th>
            <th id="t31"></th>
        </tr>
    </table>    

<script>
    function writeTable(tableID) {
        var n = document.getElementById(tableID);
        document.getElementById("t"+tableID).innerHTML = n.value;
    }
</script>

角度(c)
电压-测试1
电压-测试2
电压-测试3
电压-测试4
0
12
角度(c)
电压-测试1
电压-测试2
电压-测试3
电压-测试4
0
12
函数可写(tableID){
var n=document.getElementById(tableID);
document.getElementById(“t”+tableID).innerHTML=n.value;
}

谢谢,效果很好。只是一个简单的问题,id与“t”的组合只是为了使输出id与输入id不同吗?很抱歉,我没有理解你的意思?我问这一行是做什么的
document.getElementById(“t”+tableID”)。innerHTML=n.value    <!-- 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="0" 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="1" 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="t0"></th>
            <th id="t10"></th>
            <th id="t20"></th>
            <th id="t30"></th>
        </tr>
        <tr>
            <th> 12 </th>
            <th id="t1"> </th>
            <th id="t11"></th>
            <th id="t21"></th>
            <th id="t31"></th>
        </tr>
    </table>    

<script>
    function writeTable(tableID) {
        var n = document.getElementById(tableID);
        document.getElementById("t"+tableID).innerHTML = n.value;
    }
</script>