SlideShare une entreprise Scribd logo
JavaScript



Travail présenté par : MAHDHAOUI Ismail
Qu'est-ce que le JavaScript ?(1/2)



 Un langage de programmation:
JavaScript est un langage qui permet aux développeurs
d'écrire du code source qui sera analysé par
l'ordinateur.
 Programmer des scripts:
        Langage compilé.
        Langage pré-compilé.
        Langage interprété (exp: javascript).
Qu'est-ce que le JavaScript ?(2/2)
Premiers pas en JavaScript (1/4)



<html>
<head>
<title>Cc bjr</title>
</head>
<body>
<script>
alert('Cc bjr! ');
</script>
</body>
</html>
Premiers pas en JavaScript (2/4)


<html>
<head>
<title>Cc bjr</title>
</head>
<body>
bonjour
<script>
alert('Cc bjr! ');
</script>
&nbsp; bonjour
</body>
</html>
Premiers pas en JavaScript (3/4)

 Index.html
<html>
<head>
<title>Cc bjr</title>
<script src="Scripts.js" type="text/javascript"></script>
</head>
<body>
bonjour
</body>
</html>

 Scripts.js
alert('Cc bjr! ');
Premiers pas en JavaScript (4/4)


 Index.html
<html>
<head>
<title>Cc bjr</title>
<script src="Scripts.js" type="text/javascript"></script>
</head>
<body>
<input type="button" onclick="commencer()" value=“Go" /></body>
</html>

 Scripts.js
function commencer()
{
           alert("BJR!");
}
Où placer le code dans la page?




 Le Javascript "dans la page "

 Le Javascript externe
Les variables

 Les variables (déclaration)
 var number = 2;
 Les types de variables
toute déclaration de variable se fait avec le mot-clé var sans
distinction du contenu
 Tester l'existence de variables avec "typeof"
var number = 2;
alert(typeof number);
 // Affiche : "number"
var text = 'Mon texte';
alert(typeof text); // Affiche : "string"
var aBoolean = false;
alert(typeof aBoolean); // Affiche : "boolean"
Les conditions



Opérateur   Signification
==          égal à                                     Type de
                                           Opérateur             Utilisation
!=          différent de                               logique
===         contenu et type égal à                               valeur1
                                           &&          ET        &&
!==         contenu ou type différent de
                                                                 valeur2
>           supérieur à
                                                                 valeur1 ||
>=          supérieur ou égal à            ||          OU
                                                                 valeur2
<           inférieur à                    !           NON       !valeur
<=          inférieur ou égal à
La condition "if - else"



Exemple:

Var i =3,b;
b=5;
if ((a+b)<8) { alert(" inf"); }
else if ((a+b)>8) { alert("sup"); }
else alert(« eg");
La condition "switch"


Exemple:
var choix= (prompt('Choisissez 1 ou 2 :'));
Var nbr=parseInt(choix);
switch (nbr) {
 case 1: alert('un'); break;
 case 2: alert('deux');break;
default: alert(‘invalid');break;
}
la fonction confirm()



 Exemple:
if (confirm('Voulez-vous exécuter le code Javascript de
cette page ?'))
{
 alert('Le code a bien été exécuté !');
 }
Les boucles


 La boucle while
var number = 1;
 while (number < 10)
 { number++; alert(number);
}
 La boucle do while
var number = 1;
do
  { number++; alert(number);
}
while (number < 10)

 La boucle for
for ( i=0;i<10;i++)
{ alert(i);
}
Méthode : getElementById()


 Index.html                                                 Scripts.js
<html>                                                       function calculer()
<head>
<title>Cc bjr</title>                                        {
<script src="Scripts.js" type="text/javascript"></script>    var resultat=0;
</head>                                                      var nbr1=document.getElementById('nbr1').value;
<body>                                                       var nbr2=document.getElementById('nbr2').value;
                                                             resultat=parseInt(nbr1)+parseInt(nbr2);
<input type="text" id="nbr1" /><br />                        document.getElementById('res').value=resultat;
+<br />                                                      }
<input type="text" id="nbr2" /><br />
=<br />
<input type="text" id="res" /><br />

<input type="button" onclick=“calculer()" value=“calculer"
/></body>
</html>
Exercice d’application (formulaire)


 Index.html
<form id="f1" action="eng.php" method="post">              Scripts.js
                                                           function valider()
                                                           {
Nom<input type="text" id="nom" /><br />
                                                           var n=document.getElementById('nom').value;
                                                           var p=document.getElementById('pre').value;
Prenom<input type="text" id="pre" /><br />                 var a=document.getElementById('age').value;

Age<input type="text" id="age" /><br />                    var age=parseInt(a);
                                                           if(age<0 || age > 90)
                                                           {
<input type="button" onclick="valider()" value="valider"   alert('age invalid!!');
/>                                                         }
</form>                                                    else
                                                           {
                                                           document.getElementById('f1').submit();
                                                           }
                                                           }
Éditer les propriétés CSS


                                                                                      Stye.css
                                                                                      .style0{
                                                                                      height:100px;
                                                                                      width:100px;
 Index.html                          Scripts.js                                      background-color:red;
                                      function changer_style(n)                       }
<div id="mon_div" class="style0">d                                                    .style1{
                                      {
</div>                                                                                height:200px;
<input type="button" value="style0"   var mydiv=document.getElementById('mon_div');   width:250px;
onclick="changer_style(0)" /><br />   mydiv.className="style"+n;                      background-color:#33FF66;

<input type="button" value="style1"   }
                                                                                      }
onclick="changer_style(1)" /><br />                                                   .style2{
<input type="button" value="style2"
onclick="changer_style(2)" /><br />                                                   height:350px;
                                                                                      width:250px;
<input type="button" value="style3"
                                                                                      background-color:#FF00CC;
onclick="changer_style(3)" /><br />
                                                                                      }
                                                                                      .style3{

                                                                                      height:450px;
                                                                                      width:450px;
                                                                                      background-color:#FF0000;
                                                                                      }
Pause
Les fonctions temporelles




setTimeout(myFunction, 2000); //exécuter mon
fonction après 2 s.
Exemple
Changer le style d’un div chaque 2s.
Innerhtml



 Index.html
<div id="mon_div" >ismail
</div>                                     Scripts.js
                                           function changer_image(n)
<input type="button" value="image0"
                                           {
onclick="changer_image(0)" /><br />
<input type="button" value= "image1"       var mydiv=document.getElementById('mon_div');
onclick="changer_image(1)" /><br />        mydiv.innerHTML="<img src ='"+n+".jpg' width='200'>";
<input type="button" value= "image2"       }
onclick="changer_image(2)" /><br />
<input type="button" value= "image3"
onclick="changer_image(3)" /><br />
Fin




MERCI

Contenu connexe

PDF
Jquery : les bases
PDF
Introduction a jQuery
PDF
Jquery - introduction au langage
PDF
Comment Créer Un Site De Membres vol 03
PPT
initiation au javascript
PPTX
La première partie de la présentation PHP
PPTX
Initiation au JavaScript
Jquery : les bases
Introduction a jQuery
Jquery - introduction au langage
Comment Créer Un Site De Membres vol 03
initiation au javascript
La première partie de la présentation PHP
Initiation au JavaScript

Tendances (11)

PPT
PHP &amp; MySQL
PPT
PPT
Présentation jQuery pour débutant
PDF
Manualjquery
PPT
C5 Javascript
PPTX
La 2ème partie de la présentation PHP
PDF
Cours php & Mysql - 2éme partie
PPT
Php mysql cours
 
PDF
Unidades y conceptos
PDF
Memento HTML CSS
PPTX
PHP &amp; MySQL
Présentation jQuery pour débutant
Manualjquery
C5 Javascript
La 2ème partie de la présentation PHP
Cours php & Mysql - 2éme partie
Php mysql cours
 
Unidades y conceptos
Memento HTML CSS
Publicité

En vedette (20)

PDF
Fonderia presentazione
PDF
Politica industrialeinitalia pf
PDF
Luoghi(poco)comuni
PDF
Sinopoli contratti
PPTX
Conrad Florez Paints Sullen Argentina HQ
PPT
Babam
PPTX
PPT-Minerals
PPTX
PPT-Minerals
PPSX
GALERIA
PPT
реализация наследственной информации в клетке
PPTX
Catedral de oaxaca
PPTX
Cuilapan, oaxaca
PPTX
Tonatzintla, puebla
PPTX
Presentation2
PPTX
comportamientos digitales
PDF
Normativa abalar terminadaa
DOCX
Calendario barrial 7abril
PDF
LE NOVITA’ FISCALI 2012: ADEMPIMENTI E FORMALITA'
PPTX
Instrumentos de la música Hindú
PDF
Management Trainee Program at GSK Pakistan
Fonderia presentazione
Politica industrialeinitalia pf
Luoghi(poco)comuni
Sinopoli contratti
Conrad Florez Paints Sullen Argentina HQ
Babam
PPT-Minerals
PPT-Minerals
GALERIA
реализация наследственной информации в клетке
Catedral de oaxaca
Cuilapan, oaxaca
Tonatzintla, puebla
Presentation2
comportamientos digitales
Normativa abalar terminadaa
Calendario barrial 7abril
LE NOVITA’ FISCALI 2012: ADEMPIMENTI E FORMALITA'
Instrumentos de la música Hindú
Management Trainee Program at GSK Pakistan
Publicité

Similaire à Javascript (17)

PDF
Formulaires
DOCX
Pratique de javascript KOUAMI DJOMO
PDF
Crs javascript
DOCX
PDF
Cours java script
PDF
Découverte HTML5/CSS3
PDF
Programmer en html5, css 3 et java script (70 480)
PDF
Enib cours c.a.i. web - séance #1 - html5 css3-js - 2
PPTX
Cours javascript v1
PDF
Johnny-Five : Robotique et IoT en JavaScript
PDF
le Langage de programmation JavaScript.pdf
PPTX
javascript cours developpement nbhdjcbhdcjbn
PDF
HTML5
PPTX
HTML5 vu par Ekino
PDF
PHP #1 : introduction
PDF
Cours_JavascriptA.pdf
PPTX
582 agr-li - interface mobile - classe 1
Formulaires
Pratique de javascript KOUAMI DJOMO
Crs javascript
Cours java script
Découverte HTML5/CSS3
Programmer en html5, css 3 et java script (70 480)
Enib cours c.a.i. web - séance #1 - html5 css3-js - 2
Cours javascript v1
Johnny-Five : Robotique et IoT en JavaScript
le Langage de programmation JavaScript.pdf
javascript cours developpement nbhdjcbhdcjbn
HTML5
HTML5 vu par Ekino
PHP #1 : introduction
Cours_JavascriptA.pdf
582 agr-li - interface mobile - classe 1

Plus de karousn (9)

PDF
Modl2 rap pfe_esti
PDF
Assemblage par vues de composants
PDF
2009 m1 ensta_projet_bases_de_donnees
DOC
Template _rapport_pfe - new_copi
PDF
Modl2 rap pfe_esti
PDF
Assemblage par vues de composants
PDF
2009 m1 ensta_projet_bases_de_donnees
DOC
Template _rapport_pfe - new
PDF
Php
Modl2 rap pfe_esti
Assemblage par vues de composants
2009 m1 ensta_projet_bases_de_donnees
Template _rapport_pfe - new_copi
Modl2 rap pfe_esti
Assemblage par vues de composants
2009 m1 ensta_projet_bases_de_donnees
Template _rapport_pfe - new
Php

Javascript

  • 2. Qu'est-ce que le JavaScript ?(1/2)  Un langage de programmation: JavaScript est un langage qui permet aux développeurs d'écrire du code source qui sera analysé par l'ordinateur.  Programmer des scripts: Langage compilé. Langage pré-compilé. Langage interprété (exp: javascript).
  • 3. Qu'est-ce que le JavaScript ?(2/2)
  • 4. Premiers pas en JavaScript (1/4) <html> <head> <title>Cc bjr</title> </head> <body> <script> alert('Cc bjr! '); </script> </body> </html>
  • 5. Premiers pas en JavaScript (2/4) <html> <head> <title>Cc bjr</title> </head> <body> bonjour <script> alert('Cc bjr! '); </script> &nbsp; bonjour </body> </html>
  • 6. Premiers pas en JavaScript (3/4)  Index.html <html> <head> <title>Cc bjr</title> <script src="Scripts.js" type="text/javascript"></script> </head> <body> bonjour </body> </html>  Scripts.js alert('Cc bjr! ');
  • 7. Premiers pas en JavaScript (4/4)  Index.html <html> <head> <title>Cc bjr</title> <script src="Scripts.js" type="text/javascript"></script> </head> <body> <input type="button" onclick="commencer()" value=“Go" /></body> </html>  Scripts.js function commencer() { alert("BJR!"); }
  • 8. Où placer le code dans la page?  Le Javascript "dans la page "  Le Javascript externe
  • 9. Les variables  Les variables (déclaration)  var number = 2;  Les types de variables toute déclaration de variable se fait avec le mot-clé var sans distinction du contenu  Tester l'existence de variables avec "typeof" var number = 2; alert(typeof number); // Affiche : "number" var text = 'Mon texte'; alert(typeof text); // Affiche : "string" var aBoolean = false; alert(typeof aBoolean); // Affiche : "boolean"
  • 10. Les conditions Opérateur Signification == égal à Type de Opérateur Utilisation != différent de logique === contenu et type égal à valeur1 && ET && !== contenu ou type différent de valeur2 > supérieur à valeur1 || >= supérieur ou égal à || OU valeur2 < inférieur à ! NON !valeur <= inférieur ou égal à
  • 11. La condition "if - else" Exemple: Var i =3,b; b=5; if ((a+b)<8) { alert(" inf"); } else if ((a+b)>8) { alert("sup"); } else alert(« eg");
  • 12. La condition "switch" Exemple: var choix= (prompt('Choisissez 1 ou 2 :')); Var nbr=parseInt(choix); switch (nbr) { case 1: alert('un'); break; case 2: alert('deux');break; default: alert(‘invalid');break; }
  • 13. la fonction confirm()  Exemple: if (confirm('Voulez-vous exécuter le code Javascript de cette page ?')) { alert('Le code a bien été exécuté !'); }
  • 14. Les boucles  La boucle while var number = 1; while (number < 10) { number++; alert(number); }  La boucle do while var number = 1; do { number++; alert(number); } while (number < 10)  La boucle for for ( i=0;i<10;i++) { alert(i); }
  • 15. Méthode : getElementById()  Index.html Scripts.js <html> function calculer() <head> <title>Cc bjr</title> { <script src="Scripts.js" type="text/javascript"></script> var resultat=0; </head> var nbr1=document.getElementById('nbr1').value; <body> var nbr2=document.getElementById('nbr2').value; resultat=parseInt(nbr1)+parseInt(nbr2); <input type="text" id="nbr1" /><br /> document.getElementById('res').value=resultat; +<br /> } <input type="text" id="nbr2" /><br /> =<br /> <input type="text" id="res" /><br /> <input type="button" onclick=“calculer()" value=“calculer" /></body> </html>
  • 16. Exercice d’application (formulaire)  Index.html <form id="f1" action="eng.php" method="post"> Scripts.js function valider() { Nom<input type="text" id="nom" /><br /> var n=document.getElementById('nom').value; var p=document.getElementById('pre').value; Prenom<input type="text" id="pre" /><br /> var a=document.getElementById('age').value; Age<input type="text" id="age" /><br /> var age=parseInt(a); if(age<0 || age > 90) { <input type="button" onclick="valider()" value="valider" alert('age invalid!!'); /> } </form> else { document.getElementById('f1').submit(); } }
  • 17. Éditer les propriétés CSS Stye.css .style0{ height:100px; width:100px;  Index.html Scripts.js background-color:red; function changer_style(n) } <div id="mon_div" class="style0">d .style1{ { </div> height:200px; <input type="button" value="style0" var mydiv=document.getElementById('mon_div'); width:250px; onclick="changer_style(0)" /><br /> mydiv.className="style"+n; background-color:#33FF66; <input type="button" value="style1" } } onclick="changer_style(1)" /><br /> .style2{ <input type="button" value="style2" onclick="changer_style(2)" /><br /> height:350px; width:250px; <input type="button" value="style3" background-color:#FF00CC; onclick="changer_style(3)" /><br /> } .style3{ height:450px; width:450px; background-color:#FF0000; }
  • 18. Pause
  • 19. Les fonctions temporelles setTimeout(myFunction, 2000); //exécuter mon fonction après 2 s. Exemple Changer le style d’un div chaque 2s.
  • 20. Innerhtml  Index.html <div id="mon_div" >ismail </div> Scripts.js function changer_image(n) <input type="button" value="image0" { onclick="changer_image(0)" /><br /> <input type="button" value= "image1" var mydiv=document.getElementById('mon_div'); onclick="changer_image(1)" /><br /> mydiv.innerHTML="<img src ='"+n+".jpg' width='200'>"; <input type="button" value= "image2" } onclick="changer_image(2)" /><br /> <input type="button" value= "image3" onclick="changer_image(3)" /><br />