gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot set property innerHTML of null

转载 作者:行者123 更新时间:2023-11-30 17:37:57 30 4
gpt4 key购买 nike

HTML:

<span id="test">0</span>
<button onclick="test(test)">Test</button>

Javascript:

function test(id) {
document.getElementById(id).innerHTML = 1;
}

未捕获的类型错误:无法设置 null 的属性 innerHTML

最佳答案

<button onclick="test('test')">Test</button>

这会起作用

一个字符串被包裹在''""

关于javascript - 未捕获的类型错误 : Cannot set property innerHTML of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21657654/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com