用ID替换document.getElementById(“ id”)
看来此代码运行良好。请在回答之前先尝试一下:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Variables</h2>
<p>In this example, x, y, and z are variables.</p>
<p id="demo"></p>
<script>
let x = 7;
let y = 45;
let z = x + y;
demo.innerHTML = "The value of z is: " + z;//please note this line
</script>
</body>
</html>
这是否意味着我可以替换document.getElementById(“ id”)。只有ID。???
It seems that this code is working well. Please try it out before you answer:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Variables</h2>
<p>In this example, x, y, and z are variables.</p>
<p id="demo"></p>
<script>
let x = 7;
let y = 45;
let z = x + y;
demo.innerHTML = "The value of z is: " + z;//please note this line
</script>
</body>
</html>
Does this mean that I can replace document.getElementById("id"). with just id.???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它正在工作,但被认为是遗产和不安全。
It's working but it's considered legacy and unsafe.
看起来确实如此,并且也适用于嵌套元素...我想知道它是否在从HTML导入的其他JS文件上起作用。
Seems like it does, and it works for nested elements also... I wonder though if it works on a different js file imported from the html.