Perintah Kawalan Pergerakan (PKP) hari ke-116

JavaScript Lesson: Basic

JavaScript adalah programming HTML dan web. JavaScript menghasilkan arahan kepada komputer.

JavaScript boleh dimasukkan di <body> dan <head> di dalam HTML. JavaScript dimasukkan di dalam <script>.

<p id="demo1"></p>
<script>
document.getElementById("demo1").innerHTML = "My First JavaScript";
</script>

JavaScript boleh menukar HTML element berdasarkan ID.

<p id="demo2"></p>
<button type="button"
onclick="document.getElementById('demo2').innerHTML = Date()">
Click Here display Date and Time</button>
<p id="demo3">JavaScript can change HTML content</p>
<button type="button"
onclick="document.getElementById('demo3').innerHTML = 'Selamat Datang'">
Click Malay</button>
<button type="button"
onclick="document.getElementById('demo3').innerHTML = 'Welcome'">
Click English</button>

Variable in JavaScript

<p id="demo4">Variable</p>
<script>
var x = 5;
var y = 6;
var z = x + y;
document.getElementById("demo4").innerHTML = "Total is " + z;
</script>

Function in JavaScript

<p id="demo5">A Paragraph</p> 
<button type="button" onclick="Function1()">Run Function</button>
<script>
function Function1(){
document.getElementById("demo5").innerHTML = "Paragraph changed";
}
</script>

Contoh: http://shahrulnizam.com/web/javascript.php

Penerangan lanjut di

  1. http://www.w3schools.com/js/js_intro.asp
  2. http://www.w3schools.com/js/js_variables.asp
  3. http://www.w3schools.com/js/js_functions.asp

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.