我对JS很新,只是写了一些脚本来学习。有人能告诉我我要去哪里吗?我认为这可能只是某处的语法错误,或者我没有使用正确的功能来完成此任务。JavaScript html编辑错误
谢谢:)
HTML:
<!DOCTYPE html>
<html>
<head>
<title>javascript • 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;
}
那么,什么应该发生和不发生? – pax162
您可能不会注意任何事情,因为1:请参阅下面的关于区分大小写的答案和2:您正在更改元素的“ID”。 – putvande
检查您的错字: 正确的语法是“getElementById”。 – Rayon