강의

멘토링

로드맵

Inflearn Community Q&A

dhrmsry70905's profile image
dhrmsry70905

asked

Introduction to Web Development for Python Users A to Z Django + Bootstrap

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

Written on

·

216

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>
pythonbootstrapdjango

Answer 1

0

SungYong Lee님의 프로필 이미지
SungYong Lee
Instructor

getElementsByID 가 아니라 getElementByID 입니다. 

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

dhrmsry70905's profile image
dhrmsry70905

asked

Ask a question