Overview of Javascript and Dom: Instructor: Dr. Fang (Daisy) Tang
Overview of Javascript and Dom: Instructor: Dr. Fang (Daisy) Tang
Overview of Javascript and Dom: Instructor: Dr. Fang (Daisy) Tang
• What is JavaScript?
– It is designed to add interactivity to HTML pages
– It is a scripting language (a lightweight programming
language)
– It is an interpreted language (it executes without
preliminary compilation)
– Usually embedded directly into HTML pages
– And, Java and JavaScript are different
• Variables
• If … Else
• Switch
• Operators
• Popup Boxes
• Functions
• Loops (for, while)
• Events
• Try … Catch
• Throw
• onerror
• Special Text
• Guidelines
• String
• Date
• Array
• Boolean
• Math
• RegExp
• HTML DOM
• Example 1:
– var string1="Peter has 8 dollars and Jane has 15"
– parsestring1=string1.match(/\d+/g)
– returns the array [8,15]
• Example 2:
– var string2="(304)434-5454"
– parsestring2=string2.replace(/[\(\)-]/g, "")
– Returns "3044345454" (removes "(", ")", and "-")
• Example 3:
– var string3="1,2, 3, 4, 5"
– parsestring3=string3.split(/\s*,\s*/)
– Returns the array ["1","2","3","4","5"]
• http://www.javascriptkit.com/javatutors/re4.shtml
• Tutorials:
– http://www.w3schools.com/htmldom/default.asp
• DOM examples:
– http://www.w3schools.com/htmldom/dom_examples.asp
• Browser
• Cookies
• Validation
• Animation
• Timing
• Create your own object
• http://www.w3schools.com/dhtml/dhtml_examples.asp
• More Examples:
– http://www.pages.org/javascript/index.html
– http://www.csupomona.edu/~ftang/www/courses/C
S299-S09/examples/changestyle.html
• Form validation:
– http://www.xs4all.nl/~sbpoley/webmatters/formval.html