简体   繁体   English

JS更改内部html表单元格

[英]JS to change inner html table cell

I am self taught PHP with little js experience so it is probably something really simple, but I have made a js function to change the inner html of a table cell and added an onchange event listener on a select element to call the function. 我是具有很少js经验的自学PHP,所以这可能确实很简单,但是我制作了一个js函数来更改表格单元格的内部html,并在select元素上添加了onchange事件侦听器以调用该函数。 However nothing happens when I change the selected value and I have no idea why, considering it is so simple it should. 但是,当我更改所选值时,什么也没有发生,并且我不知道为什么,考虑到它应该是如此简单。 Please help. 请帮忙。

td that I want to change: 我想更改的TD:

        echo '<tr><td id="pastEvents">';
        for($i=0;$i<=3;$i++){
            echo '<table class="invisible"><tr><td><img src="/'.$pastEvents[$i]['banner'].'" alt="Event Banner"></td></tr><tr><td>'.$pastEvents[$i]['name'].'</td></tr></table>';
        }
        echo '</td></tr>';

Event Listener: 事件监听器:

echo '<tr><td><table class="invisible"><tr><td>Number Shown: <select name="select" onchange="changePast()"><option value="3">3</option><option value="10">10</option><option value="20">20</option><option value="all">All</option></select></td></tr></table></td></tr>';

Script: 脚本:

<script>
    function changePast(){
        var shown = document.getElementsByName("select");
        document.getElementById("pastEvents").innerhtml = "test";
    }
</script>

The correct way to use is .innerHtml() instead of .innerhtml() 正确的使用方法是.innerHtml()而不是.innerhtml()

<script>
    function changePast(){
        var shown = document.getElementsByName("select");
        document.getElementById("pastEvents").innerHtml = "test";
    }
</script>

actually it is innerHTML 实际上是innerHTML

<div id="A"></div>

document.getElementById("A").innerHTML = 'text'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM