morpe

JS lezione

Jan 11th, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //################## .html
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title>Documento senza titolo</title>
  8.  
  9. <script type="text/javascript" src="code.js">
  10.  
  11. </script>
  12.  
  13. </head>
  14.  
  15. <body>
  16. <h1>
  17. <a href="javascript: prova();">run</a>
  18. </h1>
  19. </body>
  20. </html>
  21.  
  22. //################### .JS
  23.  
  24. // funzione
  25. function prova(){
  26. var coso =20;
  27. var nemo ="fufu ";
  28. ++coso;
  29.  
  30. // usare + per unire piu stringhe
  31. // usare ++ per incrementare  di 1 la variabile
  32.  
  33. alert( nemo + "hauhauhauh " + coso);
  34. }
  35.  
  36.  
  37. ##################### esempio di IF
  38.  
  39. // si ricollega al <a href="javascript: prova();">run</a>
  40. // e incrementa di 1
  41. var conta = 1;
  42.  
  43. function prova(){
  44. var menti = true;
  45.  
  46.  
  47. if(menti){
  48.     alert("vera... " + conta);
  49.     menti = false;
  50.     ++conta;
  51.     }
  52. else
  53.     {
  54.     menti = true;
  55.     ++conta;
  56.     exit;
  57.     }
  58. alert("falsa! " + conta);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment