5FuncObj - (CS1301) Introduction to Computer Programming...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 5. Functions and Objects - 1 http://www.cs.cityu.edu.hk/~helena JavaScript JavaScript Global Functions and Objects Global Functions and Objects Introduction to JavaScript Objects and HTML Element Objects Global Functions: isFinite, isNaN, escape/unescape, eval Creation of Objects: the new operator and constructor functions Commonly used objects: Window: Math and Random Number Generation Date Array String Document and Adding Cookies Forms: Style, Cascading Style Sheets (CSS) and Dynamic HTML (DHTML) [Please switch off your phone] (CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 5. Functions and Objects - 2 http://www.cs.cityu.edu.hk/~helena What are Objects Objects : An object is a collection of named values called properties . Each property may contain any type of data, functions, and even other objects. Example: The document object may contain a form object named F1: document.F1 The form may contain 2 input box objects with names equal to n1 and n2: document.F1.n1 and document.F1.n2 The input boxes may contain several properties like: value, size, readOnly: document.F1.n1.value The properties can be examined as follows: [Refer to Lec02_Slide13_V4_MarksToGrade.htm] (CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 5. Functions and Objects - 3 http://www.cs.cityu.edu.hk/~helena What are Objects Exercise: [Refer to Lec02_Slide13_V4_MarksToGrade.htm] What will be shown by running the statements below? javascript:alert(document.F1.CGrade.readOnly) javascript:alert(document.F1.CGrade) javascript:alert(document.F1) javascript:alert(document) javascript:alert(document.write) javascript:alert(convertAll) (CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 5. Functions and Objects - 4 http://www.cs.cityu.edu.hk/~helena HTML Elements as JavaScript Objects Handling HTML Elements as JavaScript Objects Contents in a webpage are automatically represented as "objects contained in the document object" (ie. a property of the document object). 2 simple methods to refer to these contents: (1) Each element object in the webpage body, that contains an ID, can be referred using document.getElementById( id ). If it contains a pair of starting and ending tags, the HTML text in-between the tags can be referred as the innerHTML property: document.getElementById( id ).innerHTML (2) For forms and form elements, there is one more method to refer to them. Any form object is an individual property of the document, can be referred by its name....
View Full Document

This note was uploaded on 04/16/2011 for the course CS 1301 taught by Professor Dr.wong during the Winter '08 term at City University of Hong Kong.

Page1 / 59

5FuncObj - (CS1301) Introduction to Computer Programming...

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

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