• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

강의와 똑같이 따라쳤는데 안되는 경우는 무엇이 문제일까요?

20.07.07 19:59 작성 조회수 107

0

자바스크립트 부분에 .value에서 value 에 아무색도 안들어오고
검색창에 글자를 입력하면 저 함수부분이 실행이 안됩니다

<!DOCTYPE html>
<html>
<head>
	<title>나의 첫번째 html</title>

	<link rel="stylesheet" href="basic_style.css"/>
	
</head>

<body>
	<nav>
		<a href="index.html">Home</a>
	</nav>
	<h1>my first</h1>
	<p>my first paragraph</p>

	<a href="https://www.naver.com">let's go</a>

	<input type="text" name="name" id="user_name" onkeyup="doSomething()">
	<button type="button" onclick="alert('abc')">Say hi</button>

	<hr/>

	<img src="https://thumbs.dreamstime.com/b/woman-praying-free-birds-to-nature-sunset-background-woman-praying-free-birds-enjoying-nature-sunset-99680945.jpg">
	<script>
	function doSomething(){
		var name = document.getElementsById("user_name").value;
		document.getElementsById("hello").innerHTML="hi" + name + "님"
		}
	</script>
	
</body>
</html>

답변 1

답변을 작성해보세요.

0

getElementsByID 가 아니라 getElementByID 입니다. 

id로 Element를 가져오는 getElementByID를 사용하려면, 그 id를 가진 element가 있어야 합니다. 그런데 작성하신 코드에는 hello라는 id를 가진 element가 없네요.