javascript TypeError: document.getElementsByTagName("p")[0].innerHtml 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12561734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:31:26  来源:igfitidea点击:

javascript TypeError: document.getElementsByTagName("p")[0].innerHtml is not a function

javascripttypeerrorgetelementsbytagname

提问by vaanipala

I'm getting the following error for a simple function below:

对于下面的简单函数,我收到以下错误:

TypeError: document.getElementsByTagName("p")[0].innerHtml is not a function

I'm just trying to understand the usage of getElementsByTagName.

我只是想了解 getElementsByTagName 的用法。

function myFunc(){
document.getElementsByTagName("p")[0].innerHtml("hello my name is vaani");
}
</script>
</head>

<body onload="myFunc();">
<p></p>
<p></p>
<p></p>
</body>

Can someone tell me on where i'm going wrong?

有人可以告诉我我哪里出错了吗?

回答by xdazz

innerHTMLbut not innerHtml, and it is not a function, you should set the string to this property.

innerHTML但不是innerHtml,而且它不是函数,您应该将字符串设置为此属性。

document.getElementsByTagName("p")[0].innerHTML = "hello my name is vaani";

回答by Patriks

use

利用

document.getElementsByTagName("p")[0].innerHTML="hello my name is vaani";