[英]What is wrong in this javascript code about an array?
I am a beginner to javascript and I was learning about an array and coded some but it doesn't display anything on the browser.Can you help?我是 javascript 的初学者,我正在学习数组并编写了一些代码,但它没有在浏览器上显示任何内容。你能帮忙吗?
<!DOCTYPE html>
<html>
<body>
<p id="samir"></p>
<script>
var names = ["keshab", "kiran", "Pankaj"];
document.getElementByID("samir").innerHTML = names;
</script>
</body>
you ID wrong like this Id你这个ID错了
var names = ["keshab", "kiran", "Pankaj"]; document.getElementById("samir").innerHTML = names;
<html> <body> <p id="samir"></p> </body>
您的代码中有拼写错误:用 getElementById 替换 getElementByID
There is a typo in your code.您的代码中有错字。 The correct method to access an element by its ID is getElementById, with a lowercase "b" in "ById".通过 ID 访问元素的正确方法是 getElementById,在“ById”中使用小写的“b”。
Here is the corrected code:这是更正后的代码:
<!DOCTYPE html>
<html>
<body>
<p id="samir"></p>
<script>
var names = ["keshab", "kiran", "Pankaj"];
document.getElementById("samir").innerHTML = names;
</script>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.