Javascript getElementByID().innerHTML() 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11120534/
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 12:08:15 来源:igfitidea点击:
Javascript getElementByID().innerHTML() not working
提问by user1463916
I'm new to Javascript and for some reason I can't get the following code to work and it's driving me crazy!
我是 Javascript 的新手,出于某种原因,我无法让以下代码工作,这让我发疯了!
It's
它是
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="test" />
<meta name="keywords" content="test" />
<meta name="robots" content="index,follow" />
</head>
<body>
<h1>test</h1>
<p id="demo">something</p>
<button type="button" onclick="myFunction();">Try it</button>
<script type="text/javascript">
function myFunction() {
document.getElementByID("demo").innerHTML = "testttt";
}
</script>
</body>
</html>
Anyone know the problem?
有人知道问题吗?
回答by VisioN
You should use getElementById
, where the last letter is lowercase:
您应该使用getElementById
,其中最后一个字母是小写:
----------------------.
v
document.getElementById("demo")
N.B.JavaScript is a case sensitive language.
注意JavaScript 是一种区分大小写的语言。