Javascript [ External_file ]

양혜정·2024년 4월 6일
0

HTML/CSS/JS 실행

목록 보기
19/60
post-thumbnail


HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>스크립트는 html 파일과 분리된 외부경로에 파일(확장자 .js)로 저장한 후 사용할 수 있습니다.</title>
</head>
<body>
	<h1 id="h1"></h1>
	<h2>스크립트는 html 파일과 분리된 외부경로에 파일(확장자 .js)로 저장한 후 사용할 수 있습니다.</h2>
	
	<p id="demo">변경전 p태그</p>
	<button type="button" onclick="myFunction()">클릭하세요.</button>

	<script type="text/javascript" src="./js/03.js"></script>
	
</body>
</html>

JS

function myFunction() {
    document.getElementById("demo").innerHTML = "p태그의 내용이 변경되었습니다";
    document.getElementById("demo").innerHTML = "p태그의 <span style='color: blue; font-weight: bold;'>내용이 변경</span>되었습니다";
}

document.getElementById("h1").innerHTML = "<span style='color: orange;'>h1</span> 태그 입니다.";	

정리

  • 01_where_to -> 03_javascript_external_file, 03.js

0개의 댓글

관련 채용 정보