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您可能应该回答这个问题。