05Javascript - CS5281 Internet Application Development...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
CS5281 Internet Application Development JavaScript
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS5281 - JavaScript 2 Introduction z We are going to cover the following topics: z Basics of the JavaScript Language z HTML Document Object Model z HTML Event Handling z Cookies Programming z The Use of Timeout and Interval
Background image of page 2
CS5281 - JavaScript 3 What is JavaScript? z The standard client-side scripting language for most browsers z Enhance a webpage to become more dynamic and interactive z Put in webpage by using the SCRIPT element z Scripts are executed while the webpage is being loaded
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS5281 - JavaScript 4 Where to Put a SCRIPT Element z The SCRIPT element can be put in anywhere inside an HTML document z We usually put the element in one of the following sections: z Inside the HEAD element z In the middle of the BODY element
Background image of page 4
CS5281 - JavaScript 5 SCRIPT Element in the Header Section z Loaded before reading the body section of a document z Typically for scripts that contain different definitions and functions z <SCRIPT TYPE="text/javascript"> var windowWidth = 640, windowHeight = 480; function initialize() { … } function validateInput(input) { … } </SCRIPT>
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS5281 - JavaScript 6 SCRIPT Element in the Body Section z Also known as Inline Scripting z Executed at the same time the document is loaded z Usually for dynamic content generation z <SCRIPT TYPE="text/javascript"> date = new Date(); document.write(date.toLocaleString()); </SCRIPT>
Background image of page 6
CS5281 - JavaScript 7 Basics in JavaScript z Comments can be written in these formats: z // I am a single line comment z /* I am a multiple lines comment */ z <!-- This is also a comment!
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS5281 - JavaScript 8 Basics in JavaScript (cont.) z What is the use of <!-- ? z <HTML> <HEAD> <SCRIPT TYPE="text/javascript"> <!-- hidden from old browsers JavaScript here! // --> </SCRIPT> </HEAD> <BODY> … </BODY> </HTML>
Background image of page 8
CS5281 - JavaScript 9 Basics in JavaScript (cont.) z Strings are enclosed by single quotes or double quotes z "Hello, I am a string!" z Every statement can be ended by a semi-colon z document.write("Semi-colon here"); or optionally z document.write("No semi-colon")
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS5281 - JavaScript 10 Variables z Variable can be created in JavaScript by either of the following statements z var <variable name> = <initial value> z var course="CS5281" z <variable name> = <initial value> z course="CS5281" z Variable names are case sensitive
Background image of page 10
CS5281 - JavaScript 11 Variables (cont.) z Local Variable z If a variable is declared inside a function, it will be destroyed after the function finished z Global Variable z If a variable is declared outside of a function, it will be destroyed when the page is unloaded
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS5281 - JavaScript 12 Data Types z Data types in JavaScript z Number z var aNumber = 45 z String z var aString = "Hello!" z Boolean z var aBoolean = true
Background image of page 12
CS5281 - JavaScript 13 Data Types (cont.) z Data types in JavaScript z Null z null z Variable contains empty value z Undefined z undefined z Coming from any variable that is not defined
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS5281 - JavaScript 14 Implicit Typing
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/11/2011 for the course CS 5281 taught by Professor Jianyingwang during the Summer '10 term at City University of Hong Kong.

Page1 / 66

05Javascript - CS5281 Internet Application Development...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online