edited by: phạm thuận hiếu ref:w3schools.com javascript browser scripting
TRANSCRIPT
Edited by: Phạm Thuận HiếuRef: w3schools.com
JAVASCRIPT
Browser scripting
What is JS? -1
Scripting languageInteractedEmbeddedInterpretedA sequence of statementsFreeJavaScript = ECMAScript (ECMA-262)
What is JS?-2
We have to study JS. Why?
Easy to learn.Easy to practise.Working in all major browsersWe had a good knowledge of: HTML, CSS, through the previous seminar. So JS is the next step.
It’s very amazing. Trust me!
Tools
Any editors such as: Notepad, Wordpad...
I use Notepad++ to illustrate all samples.When we have a large of statements:
Use JSLint: assume, alert...Use Microsoft Script Debugger:
control, execute, debug.......
Content
What is JS?We have to study JS. Why?ToolsWhere script can be placed?JS practise
Where script can be placed?
In<head></head>, <body></body> (Use one or some<script> tags)
In external files. (NOT contain the <script></script>
tags)Example:<head><script type="text/javascript" src="xxx.js"></script></head>
JS Syntax-1-Variables
var x;var y=0;var Y;/*comments*/var z=“Hello”;var t=y;//commentsvar p = y+5;var q = p%2;var r = q/=2;var i=z+” “+”World!”;
LocalGlobal
JS Syntax-2-Comparisons&Operators
+ - * / % ++ --
= += -= *= /= %=
== != > < <=
>=&& || ! Ternary
operator
===
JS Syntax-3-Statements
If...elseSwitch ...casesLoop: for, while, do..while, for inPopup box:alert(“text”);//alert boxconfirm(“text”);//confirm boxprompt(“text”,”defaultvalue”);//input value before //entering a page.
JS Syntax-4-Functions & Events
Define a Functionfunction functionname(var1,var2,...,varX){
//some code//return value
}Events are actions that can be detected by JavaScript. Ref
JS Syntax-5-Timing Events
Use 2 methods: setTimeout & clearTimeout
Syntax:var t=setTimeout("statement",milliseconds);clearTimeout(setTimeout_variable)
JS Objects
Object Methods & attributes
String length, match(), replace(),... Ref
Date getDay(), getTime(),... Ref
Array join(), pop(),... Ref
Boolean toString(), valueOf() Ref
Math round(), random(), max()... Ref
RegExp Ref
JS Advanced & Practise
JavaScript Advanced: next seminar.
Now, let’s explore all basic examples.