자바스크립트_Javascript
Javascript: 자바스크립트는 html 문서 아무 위치에나 삽입 할 수 있습니다
enjoy-country-life
2025. 7. 5. 19:13
반응형
자바스크립트를 삽입하는 예제입니다.
<script>...</script> 사이에 기술하며, html 문서의 아무 위치에나 삽입할 수 있습니다.
예제 1: html 태그 위, head 태그 사이, body 태그에 삽입하는 예
<!DOCTYPE html>
<script>
document.write("자바스크립트는 ..." + "<br/>");
</script>
<html>
<head>
<title>JavaScript 예제</title>
<script>
document.write("HTML 문서 내부에 삽입되어 실행되며, " + "<br/>");
</script>
</head>
<body>
<script>
document.write("HTML 문서 내부, 아무 위치에나 기술할 수 있습니다." + "<br/>");
</script>
</body>
</html>
예제 2: 함수를 head 태그 내부에 정의하고 호출하는 예
<!DOCTYPE html>
<html>
<head>
<title>JavaScript 예제</title>
<script>
function hello() {
document.write("안녕하세요. 자바스크립트입니다.<br/>");
}
</script>
</head>
<body>
안녕하세요 1...<br/>
<script>hello();</script>
안녕하세요 2...<br/>
</body>
</html>
예제 3: 함수를 body 태그 내부에 정의하고 호출하는 예
<!DOCTYPE html>
<html>
<head>
<title>JavaScript 예제</title>
</head>
<body>
안녕하세요 1...<br/>
<script>
function hello() {
document.write("안녕하세요. 자바스크립트입니다.<br/>");
}
</script>
안녕하세요 2...<br/>
<script>hello();</script>
</body>
</html>
반응형