Web/JavaScript

자바스크립트의 화면 출력 방법 정리

gorae_lulu 2022. 11. 23. 15:47

1. 경고창 window.alert()

window.alert("출력");

 

 

2. HTML출력 document.write()

document.write("HTML출력");
// HTML document 이후에 document.write()의 사용은
// 존재하는 모든 HTML을 지우고 완전히 로드되기 때문에
// 테스트 용도로만 추천
<!DOCTYPE html>
<html>
    <body> 
      <h1>JavaScript 출력 테스트</h1> 
      <button onclick="document.write('HTML출력')">click</button> 
    </body>
</html> 

 

 

3. HTML요소에 출력 innerHTML

document.getElementById("test").innerHTML = '출력'; 

 

 

4. 브라우저 콘솔에 출력 console.log()

// 브라우저 F12 개발자 모드에서 확인 가능
console.log("출력");

 

 

 

출처-https://coding-restaurant.tistory.com/180

'Web > JavaScript' 카테고리의 다른 글

prototype과 prototype chain  (0) 2023.01.23
class문법  (0) 2023.01.23
정규표현식  (0) 2022.12.30
인수와 인자, Argument & Parameter  (0) 2022.11.25