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>
document.getElementById("demo1").innerHTML = "My First JavaScript";

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>
var x = 5;
var y = 6;
var z = x + y;
document.getElementById("demo4").innerHTML = "Total is " + z;

Function in JavaScript

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


Penerangan lanjut di


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.