gpt4 book ai didi

JavaScript html 编辑错误

转载 作者:行者123 更新时间:2023-11-28 15:51:41 25 4
gpt4 key购买 nike

我刚接触JS,只是写了一些脚本来学习。有人可以告诉我我哪里出错了吗?我认为这可能只是某处的语法错误,或者我没有为此任务使用正确的功能。

谢谢 :)

HTML:

<!DOCTYPE html>
<html>
<head>
<title>javascript &#8226; training</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<div id='textOff'>
Hi there this is some sample text for my JS
</div>
<input type='submit' value='show me some stuff!' onclick='show();'/>
<script>
function show() {
var text = document.getElementByID('textOff');
console.log(text); //debugging
text.id = 'mainText';
};
</script>
</body>

</html>

CSS:

body {
background-color: #17161F;
color: white;
}

#mainText {
width: 20%;
height: 30%;
font-family: Arial;
margin-left: 20%;
margin-top: 20%;
}

#textOff {
display: none;
}

最佳答案

JavaScript 区分大小写。

 getElementById // correct
getElementByID // incorrect

使用浏览器提供的 JavaScript 控制台:

TypeError: Object #<HTMLDocument> has no method 'getElementByID'

关于JavaScript html 编辑错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19587917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com