Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript innerHTML更改onclick不起作用_Javascript_Html_Innerhtml - Fatal编程技术网

JavaScript innerHTML更改onclick不起作用

JavaScript innerHTML更改onclick不起作用,javascript,html,innerhtml,Javascript,Html,Innerhtml,我想通过单击按钮来更改一段文本,但这不起作用。有什么想法吗 <div> This text should stay, <span id="x">This text should change.</span> </div> <button type="button" onclick='change()'>Change</button> <script

我想通过单击按钮来更改一段文本,但这不起作用。有什么想法吗

    <div>
        This text should stay, <span id="x">This text should change.</span>
    </div>
        <button type="button" onclick='change()'>Change</button>
            <script type="javascript/text">
                function change() {
                    document.getElementById('x').innerHTML='The text has changed.';
                }
            </script>

此文本应保留,此文本应更改。
改变
函数更改(){
document.getElementById('x').innerHTML='文本已更改';
}

我做错了什么

您的type属性错误。你根本不需要它。如果确实要包含它,请将其更改为
text/javascript

,或者干脆
完全取消“type”属性。@JosiahKeller您可能应该回答这个问题。