πŸ’»Coding/πŸ“˜ JavaScript

JavaScript _ μžλ°”μŠ€ν¬λ¦½νŠΈ μž‘μ„± μœ„μΉ˜μ™€ 연결방법

μŒμ€μ‘ 2021. 8. 23. 07:10
728x90
λ°˜μ‘ν˜•

JavaScript _μž‘μ„± μœ„μΉ˜μ™€ μ—°κ²°λ°©λ²•

JavaScript
Q : μžλ°”μŠ€ν¬λ¦½νŠΈλŠ” 어디에 μž‘μ„±ν•΄μ•Όν• κΉŒμš”?

- "μžλ°”μŠ€ν¬λ¦½νŠΈλŠ” 크게 2가지 μœ„μΉ˜μ—μ„œ μž‘μ„±ν•  수 μžˆμŠ΅λ‹ˆλ‹€."

1). λ‚΄λΆ€ μŠ€ν¬λ¦½νŠΈ
γ„΄ html λ¬Έμ„œ μ•ˆμ—μ„œ μ§μ ‘ 슀크립트λ₯Ό μž‘μ„±ν•˜λŠ” 방법

2). μ™ΈλΆ€ μŠ€ν¬λ¦½νŠΈ μž‘μ„±ν•˜λŠ” 방법
γ„΄ μžλ°”μŠ€ν¬λ¦½νŠΈ νŒŒμΌμ„ μ™ΈλΆ€μ—μ„œ λ”°λ‘œ λ§Œλ“€μ–΄μ„œ, html νŒŒμΌμ— μ—°κ²°ν•˜λŠ” 방법
γ„΄ β€»μžλ°”μŠ€ν¬λ¦½νŠΈ νŒŒμΌμ„ λ§Œλ“œλŠ” ν™•μž₯μžλŠ” jsμž…λ‹ˆλ‹€.
γ„΄ 즉, λ¬Έμ„œ μ €μž₯μ‹œ νŒŒμΌμ΄λ¦„.js λΌκ³  μ €μž₯ν•΄μ£Όμ‹œλ©΄ λ©λ‹ˆλ‹€.

[파일 μ €μž₯ μ˜ˆμ‹œ]

νŒŒμΌμ΄λ¦„.js 

 

πŸ“Œ Q : μžλ°”μŠ€ν¬λ¦½νŠΈλŠ” 어디에 μž‘μ„±ν•˜κ³ , μ™ΈλΆ€μ—μ„œ μž‘μ„±ν•œ νŒŒμΌμ€ 또 μ–΄λ–»κ²Œ λΆˆλŸ¬μ˜¬κΉŒμš”?

A : λ‚΄λΆ€μ—μ„œ μž‘μ„±ν•˜λŠ” 방법과 μ™ΈλΆ€νŒŒμΌμ€ μ—°κ²°ν•˜λŠ” 것 λͺ¨λ‘ html 파일 μ•ˆμ—μ„œ ν•©λ‹ˆλ‹€.!

(↓λ¨Όμ € μ΄λ―Έμ§€λ‘œ μœ„μΉ˜λ₯Ό ν•œλˆˆμ— ν™•μΈν•΄λ³ΌκΉŒμš”?🀩↓)

JavaScript - μž‘μ„±μœ„μΉ˜μ™€ μž‘μ„±λ°©λ²•

 

πŸ“Œ ν•˜μ§€λ§Œ, μžλ°”μŠ€ν¬λ¦½νŠΈκ°€ μ΅μˆ™ν•΄μ§ˆ λ•ŒκΉŒμ§€ μ €ν¬λŠ” λ‚΄λΆ€μ—μ„œ μž‘μ„±ν•  μ˜ˆμ •μ΄λ‹ˆ, λ‚΄λΆ€ μž‘μ„±λ²•λ§Œ μ΅ν˜€λ³ΌκΉŒμš”?!
( β€»μ™ΈλΆ€ μŠ€νƒ€μΌμ‹œνŠΈ μž‘μ„±λ°©λ²•μ€ λ‚˜μ€‘μ— μ•Œλ €λ“œλ¦΄κ»˜μš”! )

 

(↓μ•„λž˜μ˜ μ½”λ“œλ₯Ό λ³΅μ‚¬ν•΄μ„œ <head>와 <body>μ˜μ—­μ— λΆ™μ—¬λ„£μ–΄λ³΄μ„Έμš”)

<script>
     alert("headμœ„μΉ˜μ— μž‘μ„±");
</script>

 

1). 내뢀에 μžλ°”μŠ€ν¬λ¦½νŠΈ μž‘μ„±ν•˜κΈ°

β–Ά <head> μ˜μ—­μ—μ„œ μž‘μ„±ν•˜κΈ°

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>μžλ°”μŠ€ν¬λ¦½νŠΈ_head μž‘μ„±</title>
    <script>
        alert("headμœ„μΉ˜μ— μž‘μ„±");
    </script>
</head>
<body>
    
</body>
</html>

 

[ μ‹€ν–‰ν™”λ©΄ ]

headμœ„μΉ˜μ— μžλ°”μŠ€ν¬λ¦½νŠΈ μž‘μ„±ν•œ 크둬화면

 

β–Ά <body> μ˜μ—­μ—μ„œ μž‘μ„±ν•˜κΈ°

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>μžλ°”μŠ€ν¬λ¦½νŠΈ_body μž‘μ„±</title>
</head>
<body>
    <script>
        alert("body μœ„μΉ˜μ— μž‘μ„±");
    </script>
</body>
</html>

 

λ‘κ°œμ˜ 화면이 λͺ¨λ‘ λ˜‘κ°™μ΄ 보인닀면 잘 μž‘μ„±ν•˜μ‹ κ±°μ˜ˆμš”!
μ—¬λŸ¬λΆ„μ€ 이제 μžλ°”μŠ€ν¬λ¦½νŠΈμ˜ λͺ¨λ“  ν•¨μˆ˜λ₯Ό ν™”λ©΄μ—μ„œ κ΅¬ν˜„ν•  수 있게 λ˜μ—ˆμŠ΅λ‹ˆλ‹€!!πŸŽ‰πŸŽ‰πŸŽ‰

 

였늘의 μžλ°”μŠ€ν¬λ¦½νŠΈλŠ” 끝~

 

728x90
λ°˜μ‘ν˜•