我對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