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?
有人能告诉我哪里出错了吗?
2 个解决方案
#1
24
innerHTML
but 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";
#2
2
use
使用
document.getElementsByTagName("p")[0].innerHTML="hello my name is vaani";
#1
24
innerHTML
but 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";
#2
2
use
使用
document.getElementsByTagName("p")[0].innerHTML="hello my name is vaani";