edited by: phạm thuận hiếu ref:w3schools.com javascript browser scripting

14
Edited by: Phạm Thuận Hiếu Ref: w3schools.com JAVASCRIPT Browser scripting

Upload: alicia-phelps

Post on 14-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

Edited by: Phạm Thuận HiếuRef: w3schools.com

JAVASCRIPT

Browser scripting

Page 2: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

What is JS? -1

Scripting languageInteractedEmbeddedInterpretedA sequence of statementsFreeJavaScript = ECMAScript (ECMA-262)

Page 3: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

What is JS?-2

Page 4: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

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!

Page 5: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

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.......

Page 6: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

Content

What is JS?We have to study JS. Why?ToolsWhere script can be placed?JS practise

Page 7: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

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>

Page 8: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

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

Page 9: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

JS Syntax-2-Comparisons&Operators

+ - * / % ++ --

= += -= *= /= %=

== != > < <=

>=&& || ! Ternary

operator

===

Page 10: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

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.

Page 11: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

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

Page 12: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

JS Syntax-5-Timing Events

Use 2 methods: setTimeout & clearTimeout

Syntax:var t=setTimeout("statement",milliseconds);clearTimeout(setTimeout_variable)

Page 13: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

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

Page 14: Edited by: Phạm Thuận Hiếu Ref:w3schools.com JAVASCRIPT Browser scripting

JS Advanced & Practise

JavaScript Advanced: next seminar.

Now, let’s explore all basic examples.