article thumbnail image
Published 2022. 11. 8. 15:07
  • innerHTML
  • document.write()
  • window.alert()
  • console.log()

innerHTML

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My First Paragraph</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>

</body>
</html>
My First Web Page
My First Paragraph.
11

 

document.write()

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<script>
document.write(5 + 6);
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<body>

<h1>
My First Web Page
</h1>
<p>
My first paragraph.
</p>

<script>
document.write(5 + 6);
</script>

</body>
</html>

 

 

HTML 문서가 로드된 후 document.write()를 사용하면 기존 HTML이 모두 삭제됩니다 .

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<button type="button" onclick="document.write(5 + 6)">Try it</button>

</body>
</html>
11

 

 

 

window.alert()

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<script>
window.alert(5 + 6);
</script>

</body>
</html>

 

 

 

console.log()

<!DOCTYPE html>
<html>
<body>

<script>
console.log(5 + 6);
</script>

</body>
</html>

 

 

 

JavaScript Print

<!DOCTYPE html>
<html>
<body>

<button onclick="window.print()">Print this page</button>

</body>
</html>

 

 

 

 

'JavaScript' 카테고리의 다른 글

JavaScript - String  (0) 2022.11.10
JavaScript - Object  (0) 2022.11.10
Javascript - document.getElementById()  (0) 2022.09.22
Javascript - onsubmit  (0) 2022.09.22
Javascript - confirm  (0) 2022.09.04
복사했습니다!