Você está na página 1de 73

2

1. Introdução.............................................................................................................................................. 4
1.1. Histórico ......................................................................................................................................................................... 4
1.2. O quê é JavaScript?......................................................................................................................................................... 4
1.3. Java, C++ e JavaScript são a mesma coisa?.................................................................................................................... 4
1.4. O quê posso fazer com JavaScript? ................................................................................................................................ 5
1.5. O quê preciso para programar em JavaScript?................................................................................................................ 5
2. JavaScript em uma Página HTML........................................................................................................ 5
2.1. Tags de Comentário:....................................................................................................................................................... 6
2.2. Ocultando JavaScript de Navegadores mais Antigos...................................................................................................... 7
2.1. Escrevendo em uma Página – document.write( )............................................................................................................ 7
3. Caixas Pop-up ........................................................................................................................................ 7
3.1. Método alert( ) ................................................................................................................................................................ 7
3.2. Método prompt( )............................................................................................................................................................ 8
3.3. Método confirm( )........................................................................................................................................................... 8
4. Caracteres de Escape ............................................................................................................................. 8
5. Variáveis ................................................................................................................................................ 9
5.1 Globais e Locais .............................................................................................................................................................. 9
5.2. Nomes de Variáveis ...................................................................................................................................................... 10
6. Tipos de Dados em JavaScript............................................................................................................. 10
6.1. Básicos.......................................................................................................................................................................... 10
6.2. Especias ........................................................................................................................................................................ 10
7. Conversão entre Tipos de Dados ......................................................................................................... 11
7.1. Funções parseInt( ) e parseFloat( )................................................................................................................................ 11
7.2. Outros métodos de conversão de tipos de dados - Number(), String(), Boolean()........................................................ 11
7.3. Fixando e Arredondado o número de casas “decimais” - toFixed( )............................................................................. 12
8. Operadores........................................................................................................................................... 12
8.1. Aritméticos ................................................................................................................................................................... 12
8.2. Relacionais.................................................................................................................................................................... 13
8.3. Lógicos ......................................................................................................................................................................... 13
8.4. Unários Diversos .......................................................................................................................................................... 14
8.5. Operadores de Atribuição ............................................................................................................................................. 14
8.6. Operadores Diversos..................................................................................................................................................... 14
9. Funções................................................................................................................................................. 15
9.1. Formato......................................................................................................................................................................... 15
9.2. Função sem Parâmetros ................................................................................................................................................ 16
9.3. Função recebendo Parâmetros ...................................................................................................................................... 16
9.4. Função retornando Valores ........................................................................................................................................... 17
10. Strings .................................................................................................................................................. 17
10.1. Objeto Strings ............................................................................................................................................................. 17
10.2. Comprimento de String - length ................................................................................................................................. 18
10.3. Conversão de String – toUpperCase( ) e toLowerCase( ) ........................................................................................... 18
10.4. Substrings – substring( ) ............................................................................................................................................. 18
10.5. Obtendo um Único Caractere - charAt( ).................................................................................................................... 19
10.6. Localizando uma Substring - indexOf( )..................................................................................................................... 19
10.7. Localizando a Última Ocorrência de uma Substring – lastIndexOf( ) ........................................................................ 19

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
3

11. Teste e Comparação de Valores .......................................................................................................... 20


11.1. Instrução if/else........................................................................................................................................................... 20
11.2. Expressão Condicional ............................................................................................................................................... 21
11.3. Instrução switch( ) ...................................................................................................................................................... 21
12. Array .................................................................................................................................................... 22
12.1. Criando um Array Numérico ...................................................................................................................................... 22
12.2. Acessando os Elementos do Array.............................................................................................................................. 22
12.3. Criando Arrays de Strings........................................................................................................................................... 23
12.4. Criando Arrays Rapidamente...................................................................................................................................... 23
12.5. Verificando a Quantidade de Elementos de um Array................................................................................................ 23
12.6. Dividindo uma String e Armazenando-a em um Array – split( )................................................................................ 24
12.7. Remontando um Array em uma String – join( ) ......................................................................................................... 24
12.8. Classificando Elementos de um Array........................................................................................................................ 24
13. Loops .................................................................................................................................................... 25
13.1. Loop for ...................................................................................................................................................................... 25
13.2. Loop while .................................................................................................................................................................. 26
13.3. Loop do...while ........................................................................................................................................................... 26
13.4. Loop for...in ................................................................................................................................................................ 27
13.5. Criando um Loop Infinito ........................................................................................................................................... 27
13.6. Escapando de um Loop Infinito.................................................................................................................................. 28
13.7. Desprezando uma Iteração de um Loop...................................................................................................................... 28
14. Objetos Embutidos .............................................................................................................................. 29
14.1. Objeto Math ................................................................................................................................................................ 29
14.2. Trabalhando com Números......................................................................................................................................... 31
14.3. Objeto Date................................................................................................................................................................. 32
15. Instrução with ...................................................................................................................................... 34
16. Tratadores de Eventos ......................................................................................................................... 35
16.1. Respondendo a Eventos .............................................................................................................................................. 35
16.2. Objeto event................................................................................................................................................................ 39
17. Objetos Personalizados........................................................................................................................ 40
17.1. Conceitos .................................................................................................................................................................... 40
17.2. Criando Objetos Personalizados ................................................................................................................................. 41
17.3. Criando Instâncias....................................................................................................................................................... 41
17.4. Criando Instâncias Atribuindo Valores....................................................................................................................... 42
17.5. Relação de Métodos e Propriedades de Formatação................................................................................................... 42
17.6. Protótipos de Objetos.................................................................................................................................................. 43
18. Hierarquia do Objeto Browser............................................................................................................ 43
18.1. Objeto window............................................................................................................................................................ 44
18.1.2. Objeto location......................................................................................................................................................... 49
18.1.3. Objeto history .......................................................................................................................................................... 50
18.1.4. Objeto document...................................................................................................................................................... 52
18.4.5. Objeto link ............................................................................................................................................................... 54
18.4.6. Objeto anchor........................................................................................................................................................... 55
18.4.7. Objeto image............................................................................................................................................................ 56
18.4.8. Objeto form.............................................................................................................................................................. 61
19. Detecção e Diferenças entre Navegadores ........................................................................................... 68
20. Outros Scripts ...................................................................................................................................... 70
21. Bibliografia .......................................................................................................................................... 73
22. Sobre Sites... ......................................................................................................................................... 73

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
4

!""# $ %
& %
& % ' ( $
% ) * & % + ,
! - . /
! 0 ! ) )
%
1 , 2 ) $
3 0 %
4 5 5 $1 !""6 %' $13 7
0+ $ 1 1 0
8 % 2
!# ## 5 ! 9 $1 +5 /
* 5

' ) % 0
+5 : ; & %
< ' )=> +2 ? ' @ ) 5
. 5 5 ;
; ) 0 . )
A
B CD$ ; . +5 ; '
> ;

!"" # #

' +5 ) ) ' E 1 -
. + . %' + F
' +5
'
' ; G
. G

> . > HH E 1 - 4 IDI1 E >


$ 5 >
A

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
5

$ % & #

J > )

J * ;
4 ; K
D % ; K
.% ; ; & % .
K
4 +2 ) ) > % K
B +5 .% * K
B 3 ; 3 . K
' , A

' ( # #

< . ? 5 +5 @ %
< ? - . @
%; CD$ ; 0

! F ' - ' '


% ) ;
% L

# # )*( +,-

E ; CD$ . / * .0 /
E %' 5 F
. 1 ( ( 234 3/ .0 / // ' 5
. 1 ( ( 234 3/ .0 / // 1.3 é 5

5 F

' 0 * * ? @ *
) * * ) * A
5 ? @ . * ; A

E ; , CD$ F

1) .
% + B
B D D
B

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
6

67 # 1 8

1. <html>
<head>
<title> Javascript1 </title>
<script language=“javascript”>
alert(“Seja bem-vindo(a)!”);
// JavaScript no Cabeçalho da página HTML.
</script>
</head> ...

2. <html>
<head>
<title> Javascript2 </title>
<script language=“javascript” src=“arquivo_externo.js”>
// Chamando um Arquivo Externo contendo JavaScript.
</script>
</head> ...

3. <html>
<head>
<title> Javascript3 </title>
</head>
<body>
<input type=“button” value=“Mensagem” onclick=“alert(‘Ola!’);”>
<!-- JavaScript em uma “tag” HTML através de um Tratador de Eventos.
-->
</body> …

4. <html>
<head>
<title> Javascript4 </title>
</head>
<body>
<script language=“javascript”>
document.write(“Iniciando em JavaScript”);
// JavaScript no Corpo de uma página HTML.
</script>
</body> ...

+ ( ! # * 8

, +2 , ) M .
) 5 ;

67 # 1 8

// Comentando uma linha.

/* Comentando
várias linhas... */

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
7

1 9 ( # 5 (

) % 5 <script>
E ) , 5 M .% ; 3 CD$ F
<!-- Comentário em HTML -->
) ; ; CD$ . ;

67 # 1 8

<script language=“javascript”>
<!--
document.write(“Seu navegador suporta JavaScript”)
// -->
</script>

< ; ?NN@ ; C A

6 # # )*( : # ; <=

J > % ) ; . document.write( )
, $' ) . +5 ? +5 @ M
> ) ' ; CD$

67 # 1 8

<script language=“javascript”>
document.write(“Escrevendo no documento”);
</script>

* > , ) M ;
D 0 ?K@

! 7 ) >

1 . E 3 %' 5 ' ;
.% % ' . ; +2 5
+2

, 1 <=

.% . ) ; % 5 O PQ ;3

67 # 1 8

<script language=“javascript”>
alert(“Seja muito bem-vindo(a)!”);
</script>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
8

, # <=

1% . ; ) ;

1. <script language=“javascript”>
prompt(“Digite seu nome”);
</script>

. . > ; .% . 3
; R S

2. <script language=“javascript”>
origem = prompt(“Informe o seu país de origem”,“Brasil”);
</script>

. . , 0 > ; .%
5 . % 5 * +
1 ; ;

, % #< =

.% . +5 % 2 F O TQ ? @ O Q? 5 @

67 # 1 8

1. <script language=“javascript”>
resp = confirm(“Será que vai chover?”);
</script>

1 %' ; ;

$ ! 6

5 F
• ) K
• 1 +5 ? @

! ?
U% T
U D % +5 C
U 1 + 4 ; ? @
U ? @
U I
US 1 B
UV 1 ,
UU

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
9

67 # 1 8

1. <script language=“javascript”>
alert(“Um retorno de carro está\rbem no meio desta linha!“);
alert(“\”Isto não saiu como deveria!\” disse ela“);
alert(“Esta linha tem uma tabulação\taqui.“);
</script>

' @ *

' A1 B -

; ' ; ' % ; A

67 # 1 8

Nome = “Maria”;

; ; % M > ; ) )

J > ; ; %' F

var Nome1 = “José”;

1 ; Nome1 ; % +5 ; ; M > ,
; ;3 +5

J ; % >
J ; > * +5

67 # 1 8

<script language=“javascript”>
num = 1234; // Criando e atribuindo um valor à uma variável.

var msg1; // Criando uma variável por linha.


var msg2;

var num1, nome1, msg1; // Criando todas as variáveis em uma única linha.

var nome2 = “João”, num2 = “12”, msg2 = “telefone do João: 1234-5678”;


// Criando todas as variáveis e atribuindo valores, em uma única linha.

function cliente(){
var nome3=“João”; // Criando uma variável local dentro de uma função
}
</script>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
10

' 9 # @ *

; , * N * * %
5 + 0 K
; % K
'R S * 5 * 1 +5 AAA
5 ; ; %
< W M ) * ;

67 # 1 # *1 8

Total_geral
nome3
_num1
i ?) ' I@

C + ? #

> 5 ; ) ;
? . @ ; * % 0

+ ? 8

C D*

Number - * - E 4
. F 0; 1; -3; 42; 3,1415926535897932384626433832795 ou 3.76e2.
String - T 3 ? @
Ex.: “Meu nome é Guilherme”.
Boolean - , K FJ 4
. F true; false.

C 6

J ' F
Positive infinite X -
Negative infinite X -
0 -
NaN 3 % ? 5 ' * @ < ' +5
; ) 5 . 5 ) ) *
5 ; % )
! Y/ Z ! Y 3/ Z . ! / 5 5
* ,

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
11

+ 8

Null - J ) 5 ; * 0
Undefined - - ' ) + )

E ! + ?

2 > ) . F
total= 40;
document.write(“O total é ” + total);
1 +5 ; FR '[ S

1 +5 document.write() %
) ) 5 3 . 5
+5

1 . ?@ %' % . ) ) ;
' *

\ * >3 ; '
+2 % * F

E F G <= F1 <=

• parseInt(string) NN *
• ParseFloat(string) NN *

1 +2 5 0 5 5 '

67 # 1 8
! num_b = parseFloat(prompt(“Digite um número”,“”)); NN ]% ; %
alert(num_b + “é do tipo ” + typeof(num_b));

2. string_a = “45 anos de experiência!”;


num_a = parseInt(string_a);
alert(num_a); NN 1 ; ] ; [# 5 ' '
* ) ; ; 0

• +2 5 * . .

E # > 9 #B <= (<= D 1 <=

• String ;
• Number ; '
• Boolean ; %

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
12

67 # 1 8

1. a = 2;
b = String(a); //Converte a variável numérica "a" em String.
alert(typeof(b));

E F7 5 H# I # 3> F7 <=

E . ) * , ' 4. ?@

67 # 1 8

1. a = 10/3; NN 1 ; ^ ^ % ! /
document.write(a);
a = a.toFixed(2); NN ^ ^ * R S
document.write("<br>"+ a); NN ^ ^ ;F / //

% )
, ) ; K % ; > ;

J 5 #

5 ; ?% ; @F

• 5 <"=
a = 2 , b = 3; NN >3 F % ! % % /
c = a + b;
document.write(“<br>”+c); NN R S ; #

• B <>=
a = 3 , b = 1;
c = a – b;
document.write(“<br>”+c); NN R S ;

• ? <0=
a = 8 , b = 2;
c = a / b;
document.write(“<br>”+c); NN R S ; [

• , 1 1 <K=
a = 2 , b = 3;
c = a * b;
document.write(“<br>”+c); NN R S ; 7

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
13

• , 1 L ? <M=
a = 5 , b = 2;
c = a % b;
document.write(“<br>”+c); NN R S ; !

J L 1

5 +2 ?% ; @F

• , <.=
a = 5 , b = 6;
alert(a < b);

• , ( 1 <.2=
a = 3 , b = 5;
alert(a <= b);

• , </=
a = 4 , b = 6;
alert(b > a);

• , ( 1 </2=
a = 5 , b = 7;
alert(b >= a);

• ( 1 <22=
a = 3 , b = 3;
alert(a = = b);

• 9 ( 1 <N2=
a = 3 , b = 4;
alert(a != b);

J - (

5 +2 ?__ `` 5 % ; A ; @

• 6 <OO=
a = 6 , b = 3, c = 1;
alert((a > b) && (b > c)); NN ? ' ) %@ ?% ) @

• <PP=
a = 6 , b = 3, c = 1;
alert((a > b) || (b == c)); NN ? ' ) %@ ?% ' @

• 9 ( <N=
a = 6 , b = 3, c = 1;
alert(a != b); NN ? 5 ' %@

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
14

J$ Q * ?

• # %7 % 7 <""=
1. a = 5;
alert(++a + 2); NN 1 !: ; R S . . 5
alert(“a = ” + a); NN ;Z
2. a = 5;
alert(c++ + 2); NN 1 !: ; R S . +5 . 5
alert(“c = ” + c); NN ; 6

• ? # %7 % 7 <>>=
1. a = 5
b = --a + 2; NN % ! ; R S . +5 . 5 R%S % ;7
2. a = 5
b = a-- + 2; NN % ! ; R S , . +5 . 5 R%S % ;6

• Q * <>=
1. a = 2;
b = -a; NN$ R%S % ;3
2. c = -3;
d = -c; NN$ R S % ;/

• Q * <"=
+a NN$ * ? . @

J' 5 B

• 5 B )1 <2=
a = 3; NN 1 J ; R S % /
a = b = c = 5; NN 1 ; R S R%S R S % #

• ! # 8
x =+ 3; NN a ) . 2 . " /K
x =- 3; NN a ) . 2 . > /K
x =* 3; NN a ) . 2 . K /K
x =/ 3; NN a ) . 2 . 0 /K

JC ?

• ! 1>+ * < 8=
1. x = 1, y = 2;
(x > y)? alert(“Sim, x é Maior que y”): alert(“Não, x é Menor que y”);
. 5 (x > y) . ; + , +5 ?L@
; . ; + , ?F@

2. resp = (x > y)? “Sim” : “Não”; NN1 ; % ;R 5 S


1 ; “resp” ' K ;3

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
15

• ! (>D * <"=
a = “São” , b = “Paulo”;
c = a + b; NN * R S ;R 5 E S

• >Q * < R %=
1. x = 3;
alert(typeof(x)); NN ; ; .% . K % S

2, mens = “Olá!”;
alert(typeof(mens)); NN R S ; .% .

S F G

4 +2 5 +2 )
5 . )

+2 % + CD$ ;3 ) )

S F #

< +5 ' 3 >


* +5 ? + @

<html>
<head> <title> Funções </title>
<script language=”javascript”>
function nome_da_função(){
sentença1; NN +2 +5
sentença2;
...
}
</script>
</head>

<body>
Corpo da página...
<script>
nome_da_função(); NN +5 ) .
</script>
</body>
</html>

< +5 % 8 N ? @

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
16

S F #) T#

1 +5 ' . % 8 N

67 # 1 8

O Q
<script language=“javascript”>
function mens(){ NN B +5 +5 % + ;
alert(“Ola!”);
}
</script>

<script language=“javascript”>

mens(); NN +5 ;
...
mens(); NN +5

</script)

S F B ) T#

< +5 % 8 ) 5 : +5 5
>
1 +5 % ; ; ; > +5
)

67 # 1 8

<script language=”javascript”>

function mens(quem1 , quem2){ NN B +5 +5 ; ) ! )


alert(“Ola ” + quem1 + “,olá ” + quem2);
}
</script>

Chamando a função:

<script language=”javascript”>
nome1 = “Pedro”;
nome2 = “Paulo”;
mens(nome1,nome2); NN +5 ?@ 8 !
</script)

1 +5 mens() ; ; * ; nome1(Pedro) nome2 ?E @


% ; quem1 quem2
1 +5 ; . .% ; . +5 RE S RE S

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
17

S$ F @ 1

1 +2

67 # 1 8

<script language=”javascript”>
function media(a,b,c){ NN 4 +5 % 8 %
calculo =(a+b+c)/3; NN ; ;
return calculo; NN 4 +5 ;
}
</script>
<script language=”javascript”>
result = media(3,5,8); NN +5 ?@ ?/ # Z@
alert(result); NN . % ; ) % 0 ;
</script)

; +5 +5 3
% +5 % ;

U (

%M %M '
) %M ? +5 @ ) %M ? 0 @

U B4 (

E %M ? . @F , M;
. %M F

1. teste = “Isto é um teste”;

2. teste = new String(“Isto é um teste”);

3 new ) %M
. RIsto é um testeS % 3 : ; teste

E +5 % F

teste1 = “Isto é um teste. ”;


teste2 = “Somente um teste”;
teste3 = teste1 + teste2;
alert(teste3); NN .% ;F R- ' S

E %' =+ * F

teste3 =+ “!”; NN +5 . +5 * /

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
18

U ! # # (>1 ( V

E % ) ; length
%M B %M .lengthF

frase = “Este é o meu Brasil.”;


document.write(frase.length); NN1

+ %' 5 0

U ! (: Q ! <= - ; ! <=

. ' ) . . . % . 5 F
< ?@3 *
G ?@3 *

67 # 1 8

1. frase1 = “Ouvindo você esquece. Lendo você aprende. Fazendo, você sabe!”;
alert(frase1.toUpperCase( ));
. % F <J- B J b (< B J b 1EI B 41c B J b 1 A

2. alert(frase1.toLowerCase( ));
.% F > ) > > % A

U$ B ( : B (< =

% % M
' substring? @
1 % ' 0 0 > F

F # F objeto.substring(ii,if+1); F ii X 0 if X 0 ? !@

67 # 1 8

frase2 = “Os seus olhos”;


0 1 2 3 4 5 6 7 8 9 101112

document.write(frase2.substring(3,7); NN- % FR S

• 0
• 0 5 )= 3 ? @
• + % %' 0
• 0 ' 0 % K
• 0 ' % ' .
• 0 ) ) ;
• ) 0 ;

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
19

U' B #W ! > V 5 <=

' charAt? @ % ' * F


palavra = “Crepúsculo”;
document.write(palavra.charAt(3); NN- R S

• ? @' 0
• ' charAt?@ % ' 0 >

UC - 1& # B (> 7 %< =

< % +5 % '
E ' ' indexOf? @ . F

frase3 = “Brasil, meu Brasil brasileiro...”;


ind = frase3.indexOf(“Brasil”);
document.write(ind); //- 0 % F

• > % ) ) .
• 1 +5 * * AA
• ' ; 0 % .
• % 5 ; –1

J > 8 ? @ 0
) + ; ) . F

frase3 = “Brasil, meu Brasil brasileiro...”;


document.write(frase3.indexOf(“Brasil”,1)); NN- 0 F!

UE - 1& W1 # # B (:1 7 %< =

' - . ?@ ) % % * F

frase3 = “Brasil, meu Brasil brasileiro...”;


document.write(frase3.lastIndexOf(“Brasil”)); NN- 0 F!

%' 8 ? @ 0
,. . F

frase3 = “Brasil, meu Brasil brasileiro...”;


document.write(frase3.lastIndexOf(“Brasil”,11)); NN- 0 F

E 0 ; 8 +5 ,. >
% !? @ + % !? @

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
20

+ ! # @ 1

1 > ; ;

%0 1

if ' +5 +5
> FR S

67 # 1 8
a = 5;
if (a > 2) alert(“a é maior que 2”); NN . % R ' ) S

+5 +5 > (a > 2) +5
+ ) F alert(“a é maior que 2”) ; . K ; 5
,. , 0
$* +2 %' 0 ?d e@

if (a > 2) {
alert(“a é maior que 2”);
b=a;
}

else ? 5 @ ; M +5 F

if (a > 2) {
alert(“a é maior que 2”);
a = 0;
}
else
alert(“a é menor ou igual a 2”); // ; . R S 5 )

; +2 else + F

if (a > 2) {
alert(“a é maior que 2”);
a = 0;
}
else {
alert(“a é menor ou igual a 2”);
a=5;
}

+2 , && ? @ || ? @F
1. x = 2, y = 3;
if (x == 2 && y == 3) z = x + y; // ; z ;#
. ; + +2

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
21

2. x = 2, y = 4;
if (x == 2 || y == 4) w = x + y; // ; w ;#
. ; + +2

67 ! 1

' . 5 2 ; %' '

F # 8
J ; f< +5 = + ] 8 + ] K

+5 . 5 . ; + ] ;
; K ; . ; + ] ;
;

; V< =

+5 switch ) % ; ;
. 5 * % +2

dia_semana = 5;
switch (dia_semana) {
case 0 : document.write(“Domingo”);
break;
case 1 : document.write(“Segunda-feira”);
break;
case 2 : document.write(“Terça-feira”);
break;
case 3 : document.write(“Quarta-feira”);
break;
case 4 : document.write(“Quinta-feira”);
break;
case 5 : document.write(“Sexta-feira”); // ; R . 3 S
Break;
case 6 : document.write(“Sábado”);
break;
default : alert(“ Dia da semana inválido!”);
}

• 1 ; ) ; ; +5 switchK
• 1 + switch 5 ?d e@
• +5 case 0 ) ; ;
case ; +2 , ?F@ 5 . K
; ,. case ;
• 1 +5 break ' case. 5 switch
;
• default ' +2 case +2 default
5 .

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
22

5 R

< $ 1 g ; * ;
M < ) .5
1 g , ) * ; ) >
? .F @
B 3 D + 3 ( 3 ( 3 . 3 ;%
! / [ # 7
' ' E . 1 g
6? @ ' ' 0 +5
E ' 0 0 ' ? @
1 g' %M %M 1 g ; %M
)

! #5 R9 #

1 g * %M

67 # 1 8
notas = new Array(5);
notas[0] = 8.5;
notas[1] = 5.0;
notas[2] = 10.0;
notas[3] = 9.0;
notas[4] = 4.5;

• 1 3 new ; notas %M 1 g notas


; ' %M 1 gK
• * > ) 1 g #K
• 0 ' ? @K
• E % 1 g 0
?h i@F
notas[0] = 8.5;
notas[1] = 5.0;
...

5 61 # 5 R

• E * 1 g ' , +5 ) % +5

1 +5 .% > 1 g notasF
document.write(“Notas: ” + notas[0] + “, ” + notas[1] + “ e ” + notas[2]);

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
23

! 5 R (

1 g ) 1 g ' %

67 # 1 8

dia_semana = new Array(7);


dia_semana[0] = “Domingo”;
dia_semana[1] = “Segunda-feira”;
dia_semana[2] = “Terça-feira”;
dia_semana[3] = “Quarta-feira”;
dia_semana[4] = “Quinta-feira”;
dia_semana[5] = “Sexta-feira”;
dia_semana[6] = “Sábado”;

1 g ) ) ) E
' ' %M

67 # 1 8

nomes = new Array(10);


nomes[0] = “Ana Cristina”;
nomes[1] = “Pedro José”;
document.write(nomes[1].substring(6,10)); NN- '

$ ! 5 R L #

; . 1 g . F

dia_semana = new Array(“Domingo”,“Segunda-feira”,“Terça-feira”,


“Quarta-feira”,“Quinta-feira”,“Sexta-feira”,“Sábado”);

• 1 g ' ) ) ;
* 0
• ' 1 g

% - FB * > ) % A

' @ % X 61 # #5 R

1 %M 1 g %' ,) *
1 g? ) '* > 1 g
; ) ) @

67 # 1 8

pontos = new Array(20);


document.write(pontos.length); NN ;

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
24

C ? # ( 5 # & > # #5 R: 1 <=

' ?@ >
) 5 1 g
67 # 1 8
nome = “Guilherme Henrique Santos”;
partes = nome.split(“ ”);

• ' ?@ nome % +
• 1 ; partes 1 g % F

document.write(partes[0]); NN - j
document.write(partes[1]); NN - C )
document.write(partes[2]); NN -

J > length ) 1 g partes

67 # 1 8

alert(partes.length); NN . % ; /
I F ' ?@ 1 g

E L # #5 R # # (:4 <=

' M ?@ 1 g M +5

• 1 % 1 g partes 5 ? @
> M ?@
• +5 5 M 0 5

1 +5 % . 1 g partes % inteiro.
inteiro = partes.join(“ ”);
alert(inteiro); // . % ;F j C )
I F ' M ?@ 1 g

J !1 % 61 # #5 R

' ?@ 5 1 g? %' ' @


67 # 1 8
nomes = new Array(“Rafael”, “Joaquim”, “João”, “Ana”);
nomes_classif = nome.sort( );
document.write(nomes_classif); NN - ;F 1 ) 5 I
5 ' 0 nomes_classifF
alert(nomes_classif[2]); NN . % ; 5

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
25

) >

- %

' ) ? + +2 @

67 # 1 8

for (i = 1; i < 5; i++){


document.write(“Esta é a linha ”,i, “<br>”);
}

I F ' !
'
' /
' [

D CD$ +5 G ?@ ? @ %'

J0 ?@ ?H@

5 1 67 # 1 8

• 1 +5 ?i = 1@ ' . 5 ) %
; %
1 . 5 ' . * 0
• 8 ?i < 5@ ' +5 )
. ? >3 F ) i ) 1@
+5 ' +5 +5 '
• 8 ?i++@ ' +5 ) ' . +5 ? @
, . +5 % +2
+5 ' . 5 ) '

• 1 , +5 > 8 M + '
. +5 +5

! # 7 # 1 F i % 1K +5 ' F ) i'
) 5, +5 document.write(“Esta é a linha ”,i,“<br>”) é executada; '
1 iK ? +5 @
J 3 +5 ) i ) # ; '

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
26

- ;V 1

B G 5 % ;3
. ) ?G @ +5 +5
+2 5 5 .

67 # 1 8

f G 1 g?/ [ ! #@K
i = 0;
total = 0;
while (total < 10){
total += valor[i];
i++;
}
document.write(“Total = ” + total); //I FD f!

• 1 +5 +5 G > ' 0 K
• +2

! # 7 # 1 F- +5 ' K ) * ; total
) 10 i ; 1 ; 0 1 g valor ) ;
* total ; total 10 ;

E
% +2

- ;V 1

' G ? + ) @ 1 + +5 G ' )
G +5 ' +2 5 .

67 # 1 8

valor = new Array(3,2,4,1,5);


cont = 0;
total = 20;
do {
total += valor[cont];
cont++;
}
while (total < 10)

document.write(“Total = ” + total); //I FD f /

• % +2 , ? + @K
• 1 +5 > '

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
27

$ - %

' M +5
%M %' ' * % 1 g

67 # 1 8

nomes = new Array("Jonas", "Ana", "Ruth", "Tiago", "Marcos");


document.write("<ol>");
for (i in nomes) {
document.write("<li>"+nomes[i]+ "<br>");
}
document.write("</ol>");

I F !
1
/ I
[ D
# $

• i' ; 0 ! ! K
• nomes ' 1 g) ; ' 0 i;
• ' ) * 1 g

! # 7 # 1 F 0 . 1 g
CD$ K +5 ?i in nomes) 0 i
1 g nomesK +5 document.write(“<li>”+nomes[i]+”<br>”),
' . +5 1 g
K1 , CD$

' ! #- %

G % %
% > 5

67 # 1 8

j=0, n=0;
while (j < 10) {
n++;
document.write(" n = " + n);
}

C; ) 0 . 1 +5 G 3 : ; j ; 5
A . ' ) M
; ) ' ) )

5 5 ) 3 ) ; 0

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
28

C 6 #- %

C; . +5
+5 , J > +5 % T
+5 0 +

67 # 1 F

valor = new Array(2,6,5,3,10,22,35);


n=-1;
while (true) {
n++;
if (valor[n]==10) break;
document.write(valor[n]+"<br>");
}

! # 7 # 1 F 1 +5 G true
(verdade) +5 G )
.
1 +5 if 1 g' 10
'

E ? & # #-

< +5 0 . +5 ' continue


+ ) , . +5 ,. +5

67 # 1 8

j=0;
pontos = new Array(5,0,4,2,0,7,0,8,1,6);
for (i = 0; i < 10; i++) {
j=i;
if (pontos[i] == 0) continue;
document.write("Atleta número ",++j," - pontos: ",pontos[i],"<br>");
}

! # 7 # 1 F . 1 g M;
% 0 ; i' 0? @K +5 % )
. ) i ) 10 1 +5 +2 5
. K 1 g M 0 ? @ +5 continue
) +5 document G (...) M ? 5 . @
,. K M
* % ' ' document.write()K
+5 i ' !

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
29

$ B4 6#B

%M % 5 ) ) . ) )
E ' ? +2 0 % @
1 . +5 +2 'F

f% < +5 =K

. +5 ?@ %M Math ) *

67 # 1 8

1. resultado = eval("(10 * 20) + 2 - 8"); NN ; !"[

2. calculo1 = ("3*6+2");
resultado = eval (calculo1); NN ;

1 calculo1 %' * . .

- ?@ 4 ?@ ) M; % %' +2
0 ? * * @

$ B4 , V

%M $ ; %; ) >
' ' %

$ ) F G , #*

5 ) ; F

) ?
Math.E I %
? . 6!Z@
Math.LN2 I
? . 7"/@
Math.LOG2E I %
? . ! [[ @
Math.LN10 I !
? . / @
Math.LOG10E I % !
? . [/[@
Math.SQRT2 I )
? . ! [![@
Math.SQRT_2 I ) !N
? . 6 6@
Math.PI E-
? . / ![!#"@

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
30

67 # 1 8

val_pi = Math.PI;
alert(val_pi); NN . % / ![!#" 7#/#Z"6"/

, ?
Math.abs(número) I % *
? @
Math.pow(base, expoente) I ; .

Math.max(número1, número2) I *

Math.min(número1, número2) I *

Math.sqrt(número) I ) *

Math.sin(número) I *
? @
Math.asin(número) I *
? @
Math.cos(número) I *
? @
Math.acos(número) I *
? @
Math.tan(número) I *
? @
Math.atan(número) I *
? @
Math.log(número) I 0 *

% F ' . 5 ^? * @^ 3 ) ;
+5 ) ; * ; * %M ? @

67 # 1 8

base = 3;
expoente = 2;
resultado = Math.pow(base,expoente);
document.write(resultado); NN- "

$ 5 + @ 1
, ?
Math.ceil(número) I ,. )
*
Math.floor(número) I ,. )
*
Math.round(número) I *

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
31

67 # 1 8
x = 3.46;
document.write(Math.ceil(x)+”<br>"); NN - [
document.write(Math.floor(x)+”<br>"); NN - /
document.write(Math.round(x)+”<br>"); NN - /

$ ! 9H# ) >51

, ?
Math.random() I * ! ,
? 5 . 8 @

67 # 1 8

1. alert(Math.random()); NN J .% * , !
NN . F 6!["Z"7 ZZ7 [[!7
num=5;
valor= Math.floor(Math.random() * num) + 1;
document.write(valor); NN - * , ! #

! # 7 # 1 F +5 * , ?Math.random()@
) > ?num = 5@ ! ?+1@ *
' Math.floor()

$ + B 1V # 9H#

$ ! # B4 9 #B

! ?
new Number(n) %M %
Number(n) *

67 # 1 8

1. num = new Number(23); //A variável num recebe 23.


document.write("Tipo de objeto: "+ typeof(num)+" = "+num);

2. num = new Number("23"); //Apesar das aspas, num é numérico.


document.write("Tipo de objeto: "+ typeof(num)+" = "+num);

$ @ % H # * 1 #

, ?
isNaN(variável) J ' * ? % @

num = "a23.45";
(isNaN(num))?alert(num+"-True, não é número"):alert(num +"-False, é número");
NN . % F / [# 5 ' '

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
32

$ F7 9H# 51( # ! ? # 1

, ?
Number.toFixed(algarismos) 4. ? @ *
.% ,

67 # 1 8
x = 3.4656;
document.write(x.toFixed(2)); NN 1 F / [6

$ $ ! # H# # (

, ?
Number.toString(base) *
% ? @ /7

67 # 1 8

a=240;

1. document.write(typeof(a.toString())); NN- F

2. document.write(a.toString(16)); NN- F

3. document.write(a.toString(2)); NN- F !!!!

$ B4 ?

B ' %M % ) % %M
B 5 , '

1 5 ' 3 ! !"6

$ ! # B4 ?

< %M B ' 3 G )
) %M ) E ) )
F

Hoje = new Date( ); NN1


natal = new Date(“December 25, 2020 00:00:00”); NN
natal = new Date(12, 25, 2020); NN
natal = new Date(12, 25, 2020, 0, 0, 0); NN

8 5 > .
% ; ' %M

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
33

$ 51 @ 1 ?

< ' %M B F

, ?
.setDate( ) % $>
.setMonth( ) % $> ?J : !!K f @
.SetDay( ) % ?J : 7K B f @
.setYear( ) % 1 ? 0 @
.setFullYear( ) % 1 ?[ 0 @
.setTime( ) % C ? @ '
.setHours( ) % C
.setMinutes( ) % $
.SetSeconds( ) %

67 # 1 8

hoje = new Date( ); NN1


hoje.setFullYear(2020); NN1
alert(hoje);

1 . .% ; ? > @ .%
; alert() . +5
'

67 # 1 8

alert(hoje.setYear(2020)); NNI F !#Z6676Z 67#7

$ B @ 1 ?

' %' %M B

, ?
.getDate( ) % ' $>
.getMonth( ) % ' $> ?J : !!K f @
.getDay( ) % ' ?J : 7K B f @
.getYear( ) % ' 1 ? 0 @
.getFullYear( ) % ' 1 ?[ 0 @
.getTime( ) % ' C ? @
.getHours( ) % ' C
.getMinutes( ) % ' $
.getSeconds( ) % '

67 # 1 8

hoje = new Date(“Apr 24 2020”);


dia = hoje.getDate( );
alert(dia); NN . % ;F [

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
34

$ $ + B 1V #F *

1 +2 5 0 M %M B %
; F

, ?
.getTimezoneOffset( ) 4 + ; j$D
?j G $ D <D @
.toGMTString( ) %M B .
j$D
.toLocaleString( ) %M B .

67 # 1 8

hoje = new Date(“Apr 24 2020 00:00:00”);


alert(hoje.getTimezoneOffset( )); NN . % ;F !Z ?k@
alert(hoje.toGMTString( )); NN . % ;F 4 [1 /F F <D
alert(hoje.toLocaleString( )); NN . % ;F . 3 [ % F F

k3 ; 5 +5 ?! 5 E @

$ ' ! F # ?

, ?
Date.parse(string) %M B
? * ' !N !N!"6 @
Date.UTC(valor) %M B ? * '
@ <D ?j$D@

Exemplo:

document.write(Date.parse("Apr 20, 1996")); //- F Z ""7"

' ; V

1 +5 G +5 %M +5

67 # 1 # ; V8

!f ?R * S SS@K
f ?R * S SS@K
/f ?R * S SS@K
?R * F S H , V # 7? ! /@@K
?R * F RH , V # ? ! /@@K

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
35

67 # 1 ; V8
!f ?^ * !^ ^^@K
f ?^ * ^ ^^@K
/f ?^ * /^ ^^@K
; V <, V=Y
?^ * F ^ H # 7? ! /@@K
?^ * F^H# ? ! /@@K
Z

Com a instrução with não precisamos digitar o nome do objeto (Math) para utilizar seus métodos.

C + 6

0 > ; ? @
. +5 )
. +5 ; 5 ) )
; ' J >
% CD$ ?% 5 T M @
5 . +5

E +5 * 5
. *

C L 6

1 > ; ) 5
# M ; )
+5 ; ?l NS@AAA

C !1 [

) ; % 5 ) %
F

<body>
<input type="button" value="Não clique!" onclick="alert('Você clicou!!')">
</body>

C ?B1!1 [

) ; ; ) %

<body>
<b ondblclick="alert('Você clicou duas vezes!');”>
Dê um duplo clique aqui!
</b>
</body>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
36

) ; .
. * , 5 5

C , ? ;

) ; % 5 ) % %M
%; ' T

<body>
<input type="button" value="Botão"
onMouseDown="alert('Botão pressionado!');">
</body>

C $ , Q

) ; % % 5 ) % %M

<body>
<input type="button" value="Botão"
onMouseUp="alert('Botão liberado!');">
</body>

C ' ,

) ; % T
%M )

<body>
<a href="#" onMouseOver="alert(‘Ponteiro sobre o link’);"> link1 </a>
</body>

C C ,

' ) ' %
%M j $ $ ?
+5 ) +
%

<body>
<a href="#" onMouseOut="alert(‘Ponteiro fora do link’);"> link2 </a>
</body>

C E , ,

) ; % j %
; . ; .%
? '@

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
37

<head>
<script>
function moveu() {
window.status = "Coordenadas do mouse: X = "+ event.x + "Y = " + event.y;
}
</script>
</head>
<body onMouseMove="moveu();">
</body>

C J -

) ;

<body onLoad="alert(‘Que bom que você veio!’);">

C S Q -

) ; ;

<body onUnLoad="alert(‘Não se vá!’);">

C U 1

) ; 4! M J > 5
J 3

<head>
<script>
function ajuda( ){
alert(“Eu também não sei!”);
event.returnValue = false;
}
</script>
</head>
<body onHelp = “ajuda( );”>

) ; % 5

<head>
<script>
function pare( ){
alert(“Porque parou? Parou porque?”);
event.returnValue = false;
}
</script>
</head>
<body onStop = “pare( );”>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
38

C ! 7,

) ; ; ) % 5 ;
% . J > 5 J
3

<head>
<script>
function menu( ){
alert(“Pirataria não!”);
event.returnValue = false;
}
</script>
</head>
<body onContextMenu = “menu( );”>

C 5B

; % ;

<body>
<img src="imagem.gif" onAbort="alert('Disse a imagem: -Não me aborte!');">
</body>

C $ 6

) ) 5 ' ;

<body>
<img src="imagem.gif" onError="alert('Imagine uma bela imagem aqui...');">
</body>

C ' \ R? ;

) ;

<head>
<script>
function clique(){
tecla = String.fromCharCode(event.keyCode);
window.status="Você pressionou a tecla " + tecla;
}
</script>
</head>
<body onKeyDown="clique();">

. ) ' ' +5
5 < ? * @
? T g @ 5 5 %

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
39

C C \ RQ

1 ; ) ;
?< @

<body onKeyUp="clique();">

C E \ R)

) ; '
?< @

<body onKeyPress="clique();">

C J L &

) ; ; ?) @

<body onResize="alert(‘Melhor não mexer!’);">


</body>

C B4

' %M ) ' : >


% %M 8 1 %M
+2 % ) 1 0 5 F

• type D )
• target %M ? T@
• which J ' ) % 5 )
)
• modifiers )
? 1 @
• data
• x y E +5 . g )
) ;
• screenX E +5 m )
screenY E +5 n )
• keyCode , 1 -- D

67 # 1 8

<script>
function coord( ){
window.status=“Coord. X = ” + event.x + “Coord. Y = ” + event.y;
// . % . g
</script>

O% g $ $ f“ ?@K”Q OA33 +5 33Q

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
40

E B4 ) 1&

1 %' ' %M

E !

B4 F 5 % . )
% ) )

) F 5 % %M
, 8 ) %M 5 .
T F < %M %M M; ? @
@ * 1 B4 F +5

B4 F D ) ' 0 ) ) ? @
) F D ) %M ? 0 @
, 8 D ) %M ? +5 @
T 8 R S %M
@ * 1 B4 F 5 %

67 # 1 F

B4 F
) F
, F ,

>) +2 % ?
3 @ . +2 ? @ > ; 1 g
K . ;
%M F
• J > ? %M @ ) 5
+2 % ? @ +2 ) . 5 +2
? ' @
• 1 , +5 , ? 8 @
) 5 +2 ? @ ? '
; %M @ +2 . ? ' @
• ; +2 ,
? %M @

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
41

E ! B4 ) 1&

%M 5 +2 . F

B4 F
) F + D
, F - 5

<head>...
<script language=“javascritp”>
function Cadastro(v_nome, v_ender,v_tel){ NN %M ;
this.nome= v_nome;
this.ender=v_ender; NN
this.tel=v_tel;
this.impr=f_impr; NN '
}
function f_impr( ){
linha1 = “<b>Nome: ” + this.nome + “<br>”; NNB +5 ) ;
linha2 = “Endereço: ” + this.ender + “<br>”; NN ' %M
linha3 = “Telefone: ”+ this.tel + “</b><hr>”;
document.write(linha1,linha2,linha3);
}
</script>
</head>

! # 7 # 1 8

• +5 ' %M F Cadastro
• 1 this nome ender tel ' impr %M
%M M this ' % %M ) ;

• 1 nome ender tel 5 * ) % 5 ; %M


v_nome v_ender v_tel
• imprF ' ' D ' % +5 % +f_impr

E ! T

1 %M Cadastro 8 %M M
% :
<body>...
<script>
Maria = new Cadastro( ); // 8 $ .
Maria.nome=“Maria José dos Santos”; //1 % :
Maria.ender=“Rua Bela Vista, 100”;
Maria.tel=“2222-0000”;
Maria.impr(); //< ' .
</script>
</body>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
42

E$ ! T 5 B @ 1

. * ' +5 %M
)
<body>...
<script>
Jose = new Cadastro(“José Pedro dos Santos”,“Rua Alta, 33”,“3333-0000”);
Jose.impr();
Marcos = new Cadastro(“Marcos de Jesus”,“Rua Paraíso, 7”,“1111-0000”);
Marcos.impr();
</script>
</body>

E' L 1 , ) F #

4 +5 F
String.big() 1
String.small() B
String.blink() 1
String.bold() 1
String.fixed() 1 3
String.italics() 1 ;
String.fontcolor(cor) 1
String.fontsize(n) 1
String.strike() 1
String.sub() 1 %
String.sup() 1 %
String.anchor(nome) 8

67 # 1 8
<script>
nome = “José Maria”;
document.write(nome.bold()); NN - R '$ S
document.write(“Ana Paula”.italics()); NN - R1 E S ;
ON Q

4 +5 ; F
document.bgColor 1 ;
document.fgColor 1 5 ;
document.linkColor 1 5 T ;
document.alinkColor 1 5 T ;
document.vlinkColor 1 5 T ;

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
43

67 # 1 8

<script>
document.bgColor=“green”; NN 1 ;
</script>

EC ) B4

> ) %M 5 : > >3


'
Prototype ? , @' +5 %M +5

J . ' ) . ? @ 0
0 CD$ ; ' 8 F

<head>...
<script>
function titulo(n@d NN4 +5 % 8
tag_inicio = “<h” + n + “>”; NN$ 5
texto = this.toString(); NN 5 ) ;
tag_final = “</h” + n + “>”; NN$ 5
linha = tag_inicio + texto + tag_final; NN$ 5
return linha; NNI 5
}
String.prototype.tit=titulo;

NN g +5 ?@ ' %M ?@
</script>
</head>
<body>
<script>
frase=new String(“É de batalhas que se vive a vida, tente outra vez...”);
document.write(frase.tit(2)); NN< ' ?@
</script>
</body>

J B4 D ;

< ) +5 ' )
& % ; %
M ' % M

1 % %M
% G

%M % G 5 ) %M
%M

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
44

67 # 1 F

window.document.image1

. %M !' ) ' %M G G
%M G G ; ) %M % G

? ( # B4 B* # (

G G

T hi hi hi

J B4 ; ;

) %M % G ; %M G G ) M
%M G G : M ? ) ) ' @ 1
%' ' W M ' ) % ;
M % , M; ' %M F

• ) 8

J G G

1 * R 'S M F

<body>
<a href="pag1.html"
onMouseOver="window.status='Descrição da Página 1';return true"
onMouseOut="window.status='';return true"> Página 1
</a>
</body>

1 RB +5 ; !S ; ) % T
;)

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
45

• , F

J G G 1 <=

.% . ; F

<script>
window.alert(“Bom dia! ou Boa tarde! ou Boa noite?!!”);
</script>

) % 5 O PQ . ;3

J G G # <=

.% . ; ) ; +2 F

<script>
v_nome = window.prompt(“Qual é o seu nome?”,”Digite o seu nome aqui.”);
</script>

1 R( ' LS ; % + . ; RB
) S ; ; 1 ; % 0 ;
]

J $ G G % #<=

.% . ; +5 ; F

<script>
v_resp=window.confirm(“Quer ganhar um milhão agora?”);
</script>

< . ; % ; % 2 F O PQ ? @ O Q ? @ ;
; ; +5 1 ; % 0 ; ]

J ' G G +# <=

E . +5 ? @F

<script>
window.setTimeout(“alert(‘O tempo não pára!’)”,5000);
</script>

< . ; ; R 5 ; AS , #
1 0 +5 ) ; .
' . +5

J C ; ; 1 +# <=

- . +5 F

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
46

<script>
n = 0;
function atualiza(){
n++;
window.status = "contador = " + n;
temp1 = window.setTimeout("atualiza()",1000);
}
atualiza();
</script>
<body>
<a href="#" onClick="window.clearTimeout(temp1);"> Pára o contador </a>
</body>

. % 0 ? !@ +5
?@ ! +5 ' D ?@
. +5 ! >

J E ; ; <=

1% M F

</script>
janelinha=window.open(“pag1.html”,“janela1”,“width=200,height=100”);
</script>

9 7 # 1 8
janelinha 3' M ) ; % K
pag1.html 3 ' R<I S ; ) ; M E 3 %
M % + ; 5 . +

janela1 3' M ) ; % 0 : %M G G
width height 3 M M

E % % R!S ?g @ R S? @F

1B %
1 % +
,

# B %
11B %
& B1
% 11
E ) F
V (V
; V
+5 M ;
1 % +5 M ) ;

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
47

J J G G 1 <=

4 M F

<body>
<input type=“button” value=“Fecha Janela Principal” onclick=window.close();”>
NNG G ?@ M , 5 ; A
<input type=“button” value=“Fecha Nova Janela” onclick=“janelinha.close();”>
NNM ?@ M % ?M @ .
</body>

J S G G <=

E 5 ; ) %

<body>
<input type=“button” value=“Imprime esta página” onclick=“print();”>
</body>

% 5 RImprime esta páginaS ; ;

5 ' ; %M ?window@ ' ) .


M %

J U B4 F #

4 5 2 M * ) '
; 0 ' %M
) %M G G ) % ' % )
> ; O QF

<html><head><title> Frames </title></head>


<frameset cols=”*,*”>
<frame name=“ladoesquerdo” src=”pagEsq.html”>
<frame name=“ladodireito” src=”pagDir.html”>
</frameset>
</html>

• 5 R

%M M ' %M G G

> 1 g hi
5 . O Q
parent.frames[0] ' ) Rladoesquerdo” do exemplo.
parent.frames[1] ' ) Rladodireito” do exemplo.

* % ' 0 : * * 5 A

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
48

; ; 1% 3 :M
3 :M

> F

; ; 1% M K? @
) ' ? @K
) ' ? @

67 # 1 % # V 8

<html><head><title> Frames </title></head>


<frameset rows=“17%,*”>
<frame name=“cabecalho” src=“pagCab.html”>
<frameset cols=”22%,*”>
<frame name=“ladoesquerdo” src=“pagEsq.html”>
<frame name=“ladodireito” src=“pagDir.html”>
</frameset>
</frameset>
</html>

J U F # (

1 ' frames +5 >


J M > ; % RladoesquerdoS
5 %

<html><head><title> Frames </title></head>


<frameset cols=”*,*,*”>
<frame name=“ladoesquerdo” src=“pagEsq.html”>
<frame name=“meio” src=“about:blank”>
<frame name=“ladodireito” src=“about:blank”>
</frameset>
</html>

, ; “pagEsq.html” F

<html><head><title> Frames de Navegação </title></head>


<body>
<a href=“parent.meio.location=’pagMei.html’;
parent.ladodireito.location=’pagDir.html’;
self.location=’pagNova.html’;”> Carrega páginas </a>
</body> </html>

1 +5 , ; $ B

1 TR ; S ) ) ) 5
> ; )

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
49

J B4 1

%M location +2 + <I

• )

J G G V %

1 <I ; F

<script>
document.write(window.location.href);
</script>

+ ;

J > ; % + F

<script>
window.location.href=“pag1.html”;
</script>

1 ; R ! S ; M

J G G 1

1 protocol ; % httpF

<script>
document.write(window.location.protocol);
</script>

; ;

• , 8

J G G 1 <=

' reload?@ ; ? @F

<body>
<a href=“javascript:window.location.reload();”> Atualiza a Página </a>
</body>

1 T R1 E; S ; ;

J $ G G 1 <=

' replace?@ % ; , +5 5 '


AE 5 ; : ; ' % 2 +5 F

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
50

<body>
<input type=“button” value=“Abre a Página 2”
onclick=“window.location.replace(‘pag2.html’);”>
</body>

1 % 5 R1% E; S R S % ; ;

J B4 V R

%M history , +5 <I

• )

J G G g1 (V

1 length , +5 M
) +2 ) ; F

<script>
document.write(history.length);
</script>

; * ,

J G G g

1 current window.location.href ' + ;

<script>
document.write(history.current);
</script>

; <I

J G G g 7

1 next ' + ,. ; M ) ;
;3 ' % 5 +5 R1 + SF

<script>
document.write(history.next);
</script>

; ,. <I ) M;

J $ G G g

1 previous + ; M ) ;
: ' % 5 +5 RI SF

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
51

<script>
document.write(history.previous);
</script>

; <I

• ,

J ' G G g ( <=

' go() +5 ; M; - 1
+ ,. ; M; ) % 5 lS .S F

<body>
<a href=“javascript:history.go(1);”> Avançar </a>
</body>

1 T R1 + S + ,. ; ? ) M; @

1 : ; ) % 5 l TV F

<body>
<a href=“javascript:history.go(-1);”>Retroceder </a>
</body>

1 T RI S : ;

Q 1& 1 8

<body>
<a href=“javascript:history.go(-2);”>Retroceder 2 Páginas </a>
</body>

R3 S : * ; M;

J C G G gB [<=

' back?@ : ; ) % 5 l TV F

<body>
<a href=“javascript:history.back();”>Retroceder</a>
</body>

T RI S : ; ) % 5 l TV

J E G G g% ; <=

' forward?@ + ,. ; ) % 5 l .V F

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
52

<body>
<a href=“javascript:history.forward();”>Avançar</a>
</body>

J $ B4 #

%M +2 : ;

• )

J $ ; ; # QL-

1 URL window.location.href window.history.current '


+ ; F

<script>
document.write(document.URL);
</script>

J $ ; ; # 1

1 title 0 ; ) ' .% % 0 F

<script>
document.write(document.title); NN . % 0 ;
document.title=“Novo Título”; NN 1 % 0 : ;
</script>

J $ ; ; # %

1 referrer + ; ) ) ;
T ; F

<script>
document.write(document.referrer);
</script>

J $$ ; ; # 1 , %

1 lastModified * +5 ; F

<script>
document.write(document.lastModified);
</script>

) ; ; * +5

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
53

• ,

J $' ; ; # ; <=

' write?@ M; % . E
* > ; ;

<script>
document.write(“Imprimindo um texto...”);
</script>

J $C ; ; # ; 1 <=

' writeln?@ %' .


) . M * ? A@

<script>
document.writeln(“Imprimindo linha1...”);
document.writeln(“Imprimindo linha2...”);
</script>

J $E ; ; # <=

' open?@ ' *


a M J > % . .

<script>
janela1=window.open("","janela1","width=200,height=100");
function escreve(){
janela1.document.open();
janela1.document.write("Escrevendo na janela1 <br>");
janela1.document.close();
janela1.focus();
}
</script>

<body>
<input type="button" value="Escrever" onclick="escreve();">
</body>

. ) % 5 R S * janela1 ;
; R M !S

' .focus() ) janela1

?NN@ ' document.open() document.close() > ;


) * janela1 5 ;

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
54

J $J ; ; # 1 <=
' close?@ . % ' ' document.open()
? . . @

J$' B4 1 [

T ? +2 @ ; 5 %M 5
, ; CD$ T 5 5
) 5 ) % +
; ?O Q@ ;3 +2 ;3
? @ . , ;

• 5 R

T , CD$ 1 g

J$' ; ; # 1 [ ]^

T +5 1 g T hi + T ;
CD$ ' 1 g T hi 0 ? @

<body onload="document.write(document.links[0]);">
<a href="pag1.html"> página um </a>
</body>

I 3 T ; F FNNN FN !

• )

J$' ; ;1 [ ]^V %

1 + T? @F

<script>
link1 = document.links[0].href; NN + T' ; T!
</script>

+ T ; ; T!

J$' ; ;1 [ 1 (V

1 * T . ; F

<body onload="alert(document.links.length);">
<a href="pag1.html"> Página Um </a>
<a href="pag2.html"> Página Dois </a>
</body>

- ) T . ; F

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
55

J$C B4 V

1 8 ; %' 5 %M
%' 5 , ; CD$
8 5 5 ) 5 )
% + ; ?O Q@ ;3 +2 ;3
? @

• 5 R

8 , CD$ 1 g

J$C ; ; # V ]^

8 +5 1 g hi 1 8 ;
CD$ 1 g 0 ? @
F

document.anchors[0];

I 3 : 8 ;

• )

J$C ; ; V #

1 8 ; F

<body>
<a name="ancora1"> Texto... </a>
<script>
alert(document.anchors[0].name);
</script>
</body>

- 8 ; F !

J$C ; ; V 1 (V

1 * 8 . ; F

<body>
<a name=“texto1”> Texto1 texto1 texto1... </a> <br>
<a name=“texto2”> Texto2 texto2 texto2... </a> <br>
<script>
alert(document.anchors.length);
</script>
</body>

- ) 8 . ; F

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
56

J$E B4 # (

; CD$ %' 5
%M %' 5 , ; CD$
5 5 ) 5
) % + ; ?O Q@ ;3 +2
;3 ? T @

• 5 R

, CD$ 1 g

J$E ; ; # # ( ]^

g 1 ;
CD$ g 0 ? @K
0 !? @ .F

document.images[0];

I 3 : ;

• )

E % ; ; %

<body>
<img src=“imagem1.jpg” name=“img1” border=“3” height=“200” width=“300”
hspace=“20” vspace=“10” lowsrc=“preimagem.gif”>
</body>

- ; , +5 K
. +5 :

J$E ; ; # # ( ]^ #

1 0 ; F

<script>
alert(document.images[0].name); NN ; F !
</script>

J$E ; ; # # ( ]^B

1 % % 0 ; F

<script>
alert(document.images[0].border); NN ; F/
</script>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
57

J$E$ ; ; # # ( ]^ # 1

1 R S R S M;
5 ; F

<script>
alert(document.images[0].complete);
</script>

NN ; ; R S ; R S

J$E' ; ; # # ( ] ^ V (V

1 height 0 ; F

<script>
alert(document.images[0].height); NN ; F
</script>

J$EC ; ; # # ( ]^; V

1 G 0 ; F

<script>
alert(document.images[0].width); NN ; F/
</script>

J$EE ; ; # # ( ]^V

1 + 0 ; F

<script>
alert(document.images[0].hspace); NN ; F
</script>

J$EJ ; ; # # ( ]^

1 + ; F

<script>
alert(document.images[0].vspace); NN ; F!
</script>

J$ES ; ; # # ( ]^1 ;

1 G + '3
F

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
58

<script>
alert(document.images[0].lowsrc); NN ; FR S
</script>

J$E U ; ; # # ( ]^

1 + F

<script>
alert(document.images[0].src); NN ; F RR !M S
</script>

E ' 1 g images[ ] %M ' % R S


R S 0 O Q CD$ %M F

O% g f^ ? # ( G @K ?# ( @K^Q
O 2_ # ( _ f^ ! ^G f^! ^ f^ ^Q
ON% gQ

NN ; F! ? @ ? @

• + 6 # # ( 8

onLoad 3 ( ;
onAbort 3 ( ; ;
onError 3 ( ; 5 ? @

J . 0 !7 X RI S

J$E L 11

< %M +2
' I ' % 0 ) %
' T F

<body>
<a href=“#” onmouseover=“document.images[0].src=’imagem2.jpg’;”
onmouseout=“document.images[0].src=’imagem1.jpg’;”>
<img src=“imagem1.jpg” width=“250”>
</a>
</body>

. ; F “imagem1.jpg”(incluída através da tag


HTML) ' % 0 “imagem2.jpg” ) %
( “imagem1.jpg”
1 ' % width <img>
T ; , ; ?o@ 0 <I ) )

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
59

J$E ) >! ( # # (

1 5 * ;
) R S E '3
) . % +5
;

E 8 %M - ) ' 1 g
) 5 .% F

O Q
<head>
<script>
imgs = new Image( );
imgs[0]= “imagem0.jpg”;
imgs[1]= “imagem1.jpg”;
</script>
</head>

<body>
<img src=“” name=“imag1”> <br>
<img src=“” name=“imag2”>
<script>
document.images[0].src = imgs[0];
document.imag2.src=imgs[1];
</script>
</body>
O Q

! # 7 # 1 F E '3 %M Image ) ' 1 g


+5
< CD$ ? + @

1 ' )
0 ? @ 1 g images[] %M
imgs[] ) %' ' 1 gK

E ' %
name <img> % 0 %M imgs[]
E '
% name 1 g images[]

J$E 5 #

%M - D ?@ +5 +2 '
. % +5 )=> ? % ) +2
@ ) .%
; ? : ' @

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
60

67 # 1 8 ?< @F

<html><head><title> Animação 1 </title>


<script language="javascript">
img = new Image(); NN E '3 '
for(i=0;i<9;i++){
img[i]="mouse"+i+".gif";
}
i=0;
function mostra(){ NN . % +5
if (i>8) i=0;
document.images[0].src=img[i];
i++;
ID=window.setTimeout("mostra()",150);
}
</script>
<body bgcolor="brown">
<img src="mouse0.gif" border="0">
<br>
<input type="button" value="Start" onclick="mostra();">
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Stop" Imagem" onclick="window.clearTimeout(ID);">
</body>
</html>

< %M image

67 # 1 8? +5 +5 % @

<html>
<head>
<title> Animação 2 </title>
<script language="javascript">
var vai=0;
function carregaImagem(){
imagem1.src="coração.jpg";
}
function bate(){
if (vai==0){
imagem1.width=imagem1.width+10;
imagem1.height=imagem1.height+5;}
else
{imagem1.width=imagem1.width-10;
imagem1.height=imagem1.height-5;}
if (imagem1.width>480)
vai=1;
if (imagem1.width<400)
vai=0;
setTimeout("bate()", 50);}
</script>
</head>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
61

<body onLoad="carregaImagem();">
<img name="imagem1" src="" align="center" width="400" height="250">
<script language="javascript">
bate();
</script>
</body>
</html>

J$J B4 % #

E % %M ) ; CD$
D ' CD$ '
1 g B % F

.% # fR !S fR F p %S fRE DS g fR . N S/

.0% #/

• )

forms[ ].name 1 * % ;
forms[ ].action 1 * % ;
forms[ ].method 1 * % ;
forms[ ].target 1 * % ;
forms[ ].encoding 1 * % g ;
forms[ ].length 1 ) ? @ . ;

E ; 1 g hi %M 0 % R S
O Q CD$

• ,

forms[ ].submit( ) ;
forms[ ].reset( ) ;

• 5 R

.forms[ ] M ; ;

• + 6

OnSubmit a ) ; % 5 % ;
OnReset a ) ; % 5 I ;

onSubmit
; ;

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
62

J$J B4 1 #

• 5 R

.elements[ ] M ;

• )

elements[ ].name 1
elements[ ].length 1

1 g ; % ; E %M
' % R S 0 ; ?O . Q O% Q @

J$J B4 7 7

• )

.name 1
.defaultValue 1 ? 5 @
.value 1 ? ; @

• , B4 7 7

.focus( ) E % . .
.blur( ) I
.select( ) *

• + 6

onFocus a ) ;
onBlur a ) ;
onChange a ) ;
onSelect a ) ;

J$J B4 V [B 7

• )

.name 1
.value 1 ) ;
.checked 1 +5
.defaultChecked 1 +5 ;

• ,

.click( ) B; )

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
63

• + 6

onClick a ) ; ; )

J$J$ B4

• ) ( B4

.name 1
.length 1 ) % 2
.value 1 ) ;

• ) B G B4

.defaultChecked 1 ?% 5 @ ) ;

.checked 1 ) ;

• ,

.click( ) B; )

• + 6

onClick a ) ; ; )

• 5 R

.Nome[] Nome % ) ;
1 g

J$J' B4 1

• ) ( B4 1

.name 1
.length 1 ) +2
.selectedIndex 1 0 +5

• ) G B4 1

.index 1 0 +5
.defaultSelected 1
.selected 1
.name 1 +5
.text 1 . % 5 +5
.value 1 +5 ) ;

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
64

• ,

.focus( ) E %
.blur( ) I

• + 6

onFocus( ) ) ' % %M
onBlur( ) ) '
onChange( ) ) ; +5

• 5 R

.options[] 1 g +2 %M

J $ J C 67 # 1 1& # F # 1*

JJC @ 1 F # 1*

67 # 1 F? > % @

<html>
<head> <title>formulário</title>
<script language="Javascript">
function enviar(){
if (document.form1.nome_usuario.value.length<3){
alert("Nome Incompleto!");
document.form1.nome_usuario.select();
document.form1.nome_usuario.focus();
return false;
}
if (document.form1.email_usuario.value.indexOf("@")<0){
alert("Email Inválido!");
document.form1.email_usuario.select();
document.form1.email_usuario.focus();
return false;
}
if (document.form1.comentario.value.length<3){
alert("Faça só um comentariozinho!!!");
document.form1.comentario.select();
document.form1.comentario.focus();
return false;
}
if (document.form1.pesquisa[0].checked==true)
alert("Legal, pessoas inteligentes sempre gostam da minha página!!!");
else {
if (document.form1.pesquisa[1].checked==true)
alert("Poxa, você não gostou da minha página???");
else {

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
65

alert("É para responder a pesquisaaa!");


return false;
}
}
}
</script>
</head>
<body bgcolor="#666688" marginwidth="333" leftmargin="333">
<h1 align="center"><font color="#FFFFFF"> Formulário </font> </h1>
<hr>
<form name="form1" action="mailto:seuemail@prov.com.br" method="POST"
enctype="text/plain" onSubmit="return enviar();">
<i>Nome:</i><br>
<input type=text name="nome_usuario" size="52" title="Digite seu
nome"><BR><BR>
<i>E-mail:</i><br>
<input type=text name="email_usuario" size="52" title="Digite seu E-
mail"><BR><BR>
<i>Comentário:</i><br>
<textarea name="comentario" rows="05" cols="40" title="Digite seu
comentário"></textarea>
<br><br><center>
<h3> Pesquisa: </h3>
<i>Gostou da minha página???</i><br><br>
<input type="radio" name="pesquisa" value="s" title="Clique aqui!!!"> Sim
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<center>
<input type="radio" name="pesquisa" value="n" title="Não clique aqui!">
Não<br><br><br>
<input type="submit" value="Enviar"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="Limpar">
</center>
</form>
</body> </html>

67 # 1 F? > ' % ?@ @

<html>
<head> <title>formulário</title>
<script language="Javascript">
function enviar(){
if (document.form1.nome_usuario.value.length<3){
alert("Nome Incompleto!");
document.form1.nome_usuario.select();
document.form1.nome_usuario.focus();
}
else
if (document.form1.email_usuario.value.indexOf("@")<0){
alert("Email Inválido!");
document.form1.email_usuario.select();
document.form1.email_usuario.focus();
}

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
66

else document.form1.submit();
}
</script>
</head>
<body bgcolor="#6666BB" marginwidth="333" leftmargin="333">
<h1 align="center"><font color="#FFFFFF"> Formulário </font> </h1>
<hr>
<form name="form1" action="mailto:seuemail@prov.com.br" method="POST"
enctype="text/plain">
<i>Nome:</i><br>
<input type=text name="nome_usuario" size="52" title="Digite seu
nome"><BR><BR>
<i>E-mail:</i><br>
<input type=text name="email_usuario" size="52" title="Digite seu E-
mail"><BR><BR>
<input type="button" value="Enviar" onclick="enviar();">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="Limpar">
</center>
</form>
</body>
</html>

J$JC , 9 (

67 # 1 F ?$ . +5 @

<html>
<head>
<title>formulário</title>
<script language="Javascript">
function carrega_pagina(){
i = document.form1.paginas.selectedIndex;
pag = document.form1.paginas.options[i].value;
window.location = pag;
}
</script>
</head>
<body bgcolor="#6666BB" marginwidth="333" leftmargin="333">
<h1 align="center"><font color="#FFFFFF"> Menu de Navegação </font> </h1>
<hr><center>
<form name="form1">
<select name="paginas" onchange="carrega_pagina()">
<option value="pagina1.html"> Página Um </option>
<option value="pagina2.html"> Página Dois </option>
<option value="pagina3.html"> Página Três </option>
<option value="pagina4.html"> Página Quatro </option>
</select>
</form>
</center>
</body>
</html>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
67

67 # 1 F ?$ T % 5 ' @

<html>
<head>
<title>formulário</title>
<script language="Javascript">
function carrega_pagina(){
i = document.form1.paginas.selectedIndex;
pag = document.form1.paginas.options[i].value;
window.location = pag;
}
</script>
</head>
<body bgcolor="#6666BB" marginwidth="333" leftmargin="333">
<h1 align="center"><font color="#FFFFFF"> Menu de Navegação </font> </h1>
<hr><center>
<form name="form1">
<select name="paginas">
<option value="pagina1.html"> Página Um </option>
<option value="pagina2.html"> Página Dois </option>
<option value="pagina3.html"> Página Três </option>
<option value="pagina4.html"> Página Quatro </option>
</select>
<input type="button" value="OK" onclick="carrega_pagina();">
</form>
</center>
</body>
</html>

J$JC L 1 (

<html>
<script language="JavaScript">
function relogio(){
var hoje = new Date();
var horas = hoje.getHours();
var minutos = hoje.getMinutes();
var segundos = hoje.getSeconds();
var val_horas = ((horas < 10) ? "0":"") + horas;
val_horas += ((minutos < 10) ? ":0":":") + minutos;
val_horas += ((segundos < 10) ? ":0":":") + segundos;
document.relog.visor.value = val_horas;
window.setTimeout("relogio()",500);
}
</script>
<head>
<title>Java Script - Relógio</title>
</head>

<body onLoad="relogio();" bgcolor="FFFFCC">


<center>
<hr size="2">

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
68

<font size=+3 face="Colonna MT,Brush Script MT">Relógio</font>


<hr size="2">
<br>
Relógio:<br>
<form name="relog" onSubmit="0">
<input type="text" name="visor" size="05">
</form>
</center>
</body>
</html>

J$JC$ - ?( 1

<html>
<head>
<title>Marquee comJavaScript</title>

<script>
i=0;
function marquee(){
mens=" Coloque a sua mensagem aqui... ";
document.f1.texto.value = mens.substring(i,mens.length)+mens.substring(0, i-1);

if (i < mens.length){
i++;
}
else {
i=0;
}

window.setTimeout("marquee()",200)
}

</script>
</head>

<body onLoad="marquee()" bgcolor="#546365">


<center>
<form name="f1">
<input type="text" name="texto" size="40">
</form>
</center>
</body>
</html>

S ? ?% 9 (

%M ) +2 %
; 5 ' ) %M ' ; )
;

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
69

S % # G B 9 ( 5 1

• ) 8

! 9 # , R$ S
9 #
@ J 5
5( % + ; 3 )
& % ) ; & % -
+2 5
R #- ( ( - a , S S >
R 3% S >
1 % # E R& / S
R$ EE S

D 5 ' R SF

67 # 1 F ?- @

<html>
<head> <title> Navegadores </title>
</head>
<body>
<h1 align="center"> Propriedades do Navegador Atual </h1>
<script language="javascript">
for (i in navigator){
document.write("propriedade: " + i + "<br>") ;
document.write("conteúdo: " + navigator[i] + "<hr>");
}
</script>
</body>
</html>

67 # 1 F ?- < @

<html>
<head>
<script language="javascript">
if (navigator.appName.indexOf("Netscape") > -1)
alert("Você esta utilizando o Netscape ou um Navegador Compatível");
else
if (navigator.appName.indexOf("Microsoft") > -1)
alert("Você esta utilizando o I. Explorer ou um Navegador Compatível");
else
alert("Seu navegador não é o Internet Explorer nem o Netscape");
</script>
</head>

1
% .F * $ 4 .'

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
70

U ! [

< T ' +5 ? )=> @)


; > ,
1 5 T ) 5 . 5
) ? T @
T ? @
T ; >

$ M ) T % +2
0 % ; ) 5 ' D +2
T 5 +2 ) > ? @

• ) 8

67 # 1 8

) >6 ? ! [

<html>
<head>
<title>Página armazenando um cookie</title>

<script language="javascript">
hoje= new Date();
function criaCookie(){
linha1=document.formCookie1.seunome.value;
linha2="*" + document.URL;
linha3="*" + hoje.toGMTString();
document.cookie=linha1+linha2+linha3;
}
</script>
</head>
<body bgcolor="beige">
<h2 align="center"> Carrega dados no Cookie </h2>
<form name="formCookie1">
Seu nome:<br><input type="text" name="seunome" size="50"
onChange="criaCookie()">
</form>
<input type="button" value="Lê cookie em outra página"
onClick="window.location='cookieExibe.html';"><br><br>
<input type="button" value="Limpa Cookie" onClick="document.cookie=''";>
</body>
</html>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
71

) : 67 B ? )*( 5 5 # & ! [

<html>
<head>
<title> Página exibindo cookie </title>

<script language="javascript">
function exibeCookie(){
meuCookie=document.cookie;
dados=meuCookie.split("*");
document.formCookie2.usuario.value=dados[0];
document.formCookie2.pagina.value=dados[1];
document.formCookie2.dataCookie.value=dados[2];
}
</script>

</head>
<body bgcolor="#6688BB" onLoad="exibeCookie()">

<h2 align="center"> Exibe Cookie </h2>

<form name="formCookie2">
Nome:<br><input type="text" name="usuario" size="50"><br><br>
Página anterior:<br><input type="text" name="pagina" size="50"><br><br>
Data da criação do cookie:<br><input type="text" name="dataCookie"
size="50"><br>
</form>
</body>
</html>

U ? D L 1 ( #5 # #

<html>
<head>
<title> Sobe Tela </title>
<script language="javascript">
contador=0;

function sobetela(){
if ((contador+=3)>600)
contador=0;
self.scroll(0,contador);
setTimeout('sobetela()',200);
}
</script>
<body onLoad="sobetela()">
Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
72

Texto..<br> texto....<br> texto....<br>


Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>
Texto..<br> texto....<br> texto....<br>
</body>
</html>

U 67 B L 1 + 1

<html>
<head><title> screen </title>
</head>
<script language="javascript">
document.write("<b> Sua resolução:<b>");
document.write(screen.width+"x"+screen.height);
</script>
<body bgcolor="beige">
</body>
</html>

U$ , # # # ( # ? 1& ? +,-
?BCD$ f CD$ H H @

<html>
<head>
<title> Setas de direção</title>
<script>
function clique() {
tecla = event.keyCode;
window.status="Você pressionou a tecla " + tecla;

if (tecla==37) NN : )
img1.style.pixelLeft-=5; NN - +5 -
else
if (tecla==38) NN
img1.style.pixelTop-=5; NN - +5 -
else
if (tecla==39) NN \
img1.style.pixelLeft+=5;
else
if (tecla==40) NN % .
img1.style.pixelTop+=5;
else
alert("tecla iválida!");
}
NN - +5 F ! !
</script>
</head>

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos
73

<body onKeyDown="clique();">
<img id="img1" src="imagem1.jpg" width="150"
style="position:absolute; top='100'; left='100';">
</body>
</html>

U ' 67 # #

<html>
<head>
<script>
function tocar(som){ NN % 0 ? @) ; 1 g
document.embeds[som].play();NN - +5
}
</script>
</head>
<body onKeyDown="tocar(0);">
<embed src="Sinfonia No 9 de Beethoven (scherzo).wma" hidden="true"
autostart="false">
</body>
</html>

NN - ' ?@

embeds[]é um Array de de sons e vídeos. Podemos incluir vários arquivos de som na


página e executá-los aleatoriamente,variando os índices randomicamente.

D B1 ( %

• : A %
B 4 X 4 T G
T
[

• # '
1 P g3C P P g3C
$ T T
!

• >5 # $
$ $

!"""

E ) - 4 ; ; .
%' 5 ) +
J A

Faculdade de Tecnologia de São de Paulo


Profª Elisabete da Silva Santos

Você também pode gostar