본문 바로가기

JavaScript

퇴근 후 JS-Tutorial 1(w3schools)

반응형

https://www.w3schools.com/js/js_whereto.asp

 

JavaScript Where To

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

1. 자바 스크립트 코드는 script tag 사이에 삽입된다.

<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>

 

2. 자바스크립트 function은 event가 발생했을때 실행한다. 즉 버튼을 누르면 함수가 실행된다.

 

3. body, head tag에도 스크립트를 넣을 수 있다.

 

script에 넣는다고 되어있던데 body랑 head tag에 넣는다니 무슨소리지 했는데

 

예제를 보니 head tag에 script tag를 쓴답니다.

 

즉, 자바 스크립트는 <script></script> 있어  쓸 수있다.

 

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
</head>
<body>

<h2>Demo JavaScript in Head</h2>

<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>

</body>
</html>

 

4. Placing scripts at the bottom of the <body> element improves the display speed, because script interpretation slows down the display.

 

body tag에 다는 것이 속도면에서 더 좋다.

 

5. 간단하게 js파일은 외부 스크립트고 src로 이걸 삽입하면 여기 함수 마음대로 쓸 수 있다.

 

 

<script src="myScript.js"></script>

 

 

결론~

 

자바스크립트는 이벤트 발생했을때 쓰는 함수이며, 서비스다.

 

728x90