如何连续HTML中进行数字更新和显示?
到目前为止,我被困在这里。结果,我继续得到Nan。我尝试从段落开始和获取数字0开始,但返回“无法读取null的属性(读取'addeventListener')”
<html>
<style>
</style>
<body>
<p id="result" value=0>
0
</p>
<button id="func">RUN IT</button>
<script>
document.getElementById("func").addEventListener("click", () => {
var n = document.getElementById("result");
console.log(result);
if (n != 10) {
n++;
document.getElementById("result").innerHtml = n;
}});
</script>
</body>
</html>
So far I'm stuck here. I continue to get NAN as a result. I tried by starting off with a paragraph and fetching number 0 but returns "cannot read properties of null (reading 'addEventListener')"
<html>
<style>
</style>
<body>
<p id="result" value=0>
0
</p>
<button id="func">RUN IT</button>
<script>
document.getElementById("func").addEventListener("click", () => {
var n = document.getElementById("result");
console.log(result);
if (n != 10) {
n++;
document.getElementById("result").innerHtml = n;
}});
</script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解您的问题,则每次点击按钮时,都需要将10添加到结果中。
我希望我能帮助
If I understand your problem correctly, you want to add 10 to the result every time the button is clicked.
I hope I could have helped