Javascript로 HTML 요소 출력
Javascript 코드로 HTML 요소를 웹 페이지에
직접 삽입하여 브라우저에 출력되게 할 수 있음
document.write() 또는 document.writeln()
* writeln은 줄바꿈('\n') 문자가 삽입되지만
HTML은 줄바꿈 문자를 인식하지 않으므로
<pre> 태그를 사용하여 줄바꿈을 표현하거나
<br>을 직접 전달하여 줄바꿈을 구현
☆ Code
<!doctype html>
<html>
<head>
<title>document.write</title>
</head>
<body>
<h1>document.write를 사용하여 요소 삽입하기</h1>
<hr>
</body>
<script>
document.write("<h3>Welcome</h3>");
document.write("<pre>");
document.writeln("Hello Hello");
document.writeln(" Are there Jaesoo??");
document.writeln(" Aren't there Jaesoo??");
document.write("</pre>");
with(document){
write("<h3>You're welcome이 수동태라는데?</h3>");
write("<pre>");
writeln("Good Afternoon");
writeln("2 + 5는 도대체 무엇인가?");
writeln("<strong>" + (2+5) + "</strong>임을 알아냈다");
write("</pre>");
}
</script>
</html>
'JavaScript' 카테고리의 다른 글
JS 콜백 (0) | 2024.12.02 |
---|---|
JS json (0) | 2024.12.01 |
JS 객체 (0) | 2024.12.01 |
JS 지역변수와 전역변수 (0) | 2024.11.26 |
JS 다이얼로그 (0) | 2024.11.26 |