Bagaimana cara menampilkan Output dalam javascript?
Ada 4 cara untuk menampilkan Output dalam JavaScript.
1. Menggunakan inner.html;
<!DOCTYPE html>
<html>
<head>
<title>Bagus April</title>
</head>
<body>
<h1>Fundamental Javascript (Part 2: Javascript Output)</h1>
<p id="tutor"></p>
<script >
document.getElementById("tutor").innerHTML = "<p> Aku suka Javascript </p>";
</script>
</body>
</html>
<!DOCTYPE html> <html> <head> <title>Bagus April</title> </head> <body> <h1>Fundamental Javascript (Part 2: Javascript Output)</h1> <p id="tutor"></p>
<script > document.getElementById("tutor").innerHTML = "<p> Aku suka Javascript </p>"; </script> </body> </html>
2. Menggunakan fungsi document.write();
<!DOCTYPE html>
<html>
<head>
<title>Bagoes Aprils</title>
<script>
document.write("<h1>Hello World!</h1>");
document.write("<hr>");
document.write("<p> Saya sedang belajar Javascript");
document.write("<p> Alhamdulillah ");
document.write("<hr>");
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html> <html> <head> <title>Bagoes Aprils</title> <script> document.write("<h1>Hello World!</h1>"); document.write("<hr>"); document.write("<p> Saya sedang belajar Javascript"); document.write("<p> Alhamdulillah "); document.write("<hr>"); </script> </head> <body> </body> </html>
3. Menggunakan fungsi console.log();
- Fungsi console.log() adalah fungsi untuk menampilkan teks ke console Javascript
- Contoh:
<!DOCTYPE html> <html> <head> <title>Bagus April</title> </head> <body> <script > console.log("Hello World!"); </script> </body> </html>
4. Menggunakan fungsi alert().
<!DOCTYPE html> <html> <head> <title>Bagoes Aprils</title> <script> alert("Selamat datang di tutorial belajar Javascript"); function sayHello(){ alert("Hello!"); } </script> </head> <body> <button onclick="sayHello()">Klik Aku!</button> </body> </html>
Source Code bisa di Download disini
Terima Kasih!
Beberapa referensi dari:
Tidak ada komentar:
Posting Komentar