JavaScript

자바스크립트 선언문

자바스크립트 선언문

  • 자바스크립트 구문을 실행하기 위해서는 선언문을 입력해야 합니다.
  • <head> 영역이나 <body> 영역에 선언하면 됩니다.
  • <head> 영역
<html>
<head>
<script type="text/javascript">
    javascript statements;
</script>
</head>
<body>
    
</body>
</html>

 

  • <body> 영역
<html>
<head>        
</head>
<body>
    <script type="text/javascript">
        javascritp statements;
    </script>
</body>
</html>

 

 

 

자바스크립트 위치

  • 자바스크립트 코드가 html 상에서 올 수 있는 위치는 3곳입니다.
  • Inner
  • Outside
  • Inline

 

  • Inner
  • 자바스크립트 코드가 html 문서 안에 있습니다.
<html>
<head>
    <title>My First Javascript </title>

    <script>
        document.write("Hello World!");
    </script>

</head>
<body>

</body>
</html>

 

  • Outside
  • 자바스크립트 파일을 외부에서 html 문서로 가져오는 형태 입니다. 자바스크립트 파일은 'js' 확장자를 사용합니다.
<html>
<head>
    <script src="helloworld.js"></script>
</head>
<body>
</body>
</html>

 

  • Inline
  • html에서 사용하는 태그 안에서 onclick="alert('helloworld!!.')" 와 같이 자바스크립트 구문이 사용되는 형태입니다.
<html>
<body>
    <button type="button" onclick="alert(‘helloworld!!.’)”>click button!</button>
</body>
</html>

 

 

 

 

댓글

댓글 본문
버전 관리
KNUT X LIKE LION
현재 버전
선택 버전
graphittie 자세히 보기