WEB/html,CSS
[html][js] html<script>/ js파일연결하기/src
자바칩 프라푸치노
2021. 4. 8. 17:21
2021.04.08 - [WEB/html] - [html][js] html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<!-- <script type="text/javascript" src="./js/main.js" defer></script> -->
</head>
<body>
<div id="my-name">javachip ppchino</div>
<script src="./js/main.js">
console.log('안녕하세요');
</script>
</body>
</html>
|
cs |
body에 script에 src로 js파일을 넣고
그 밑에 script안에 내용을 적으면
js파일에 있는 것만 실행이 되고 script태그 안에 있는 내용은 무시되어 실행되지 않습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<script type="text/javascript" src="./js/main.js" defer></script>
</head>
<body>
<div id="my-name">javachip ppchino</div>
</body>
</html>
|
cs |
head에 script를 연결할때는 type을 설정해주고 src로 자바스크립트 파일을 연결하고 defer을 써줍니다.
728x90