Advertisement
hercioneto

PW1 2018 paginaExemploJs.html

Sep 27th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.72 KB | None | 0 0
  1. <!-- paginaExemploJs.html -->
  2. <html>
  3. <head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.     <title>Página Exemplo Js</title>
  6.  
  7.      <script>
  8. function carregar() {
  9.     alert("Carregou a página");
  10. }
  11.  
  12. function clique() {
  13.     alert("Você clicou"); 
  14. }
  15. function clique2() {
  16.     var variavel = document.getElementById("valor").value;
  17.     alert("Você digitou: "+ variavel);    
  18. }
  19.  
  20. function escreve() {
  21. var today = new Date();
  22. var dd = today.getDate();
  23. var mm = today.getMonth()+1;
  24. var yyyy = today.getFullYear();
  25. if(dd<10)
  26. dd = "0" + dd;
  27. if(mm<10)
  28. mm = "0" + mm;
  29. today = dd + "-" + mm + "-" + yyyy;
  30. document.write("<b>" + today + "</b>");
  31. }  
  32.  
  33. function escreve2() {
  34. var elemento = document.getElementById('elemento');
  35. elemento.innerHTML = "Oi, tudo bem?"
  36. var elemento2 = document.getElementById('valor');
  37. elemento2.value= "teste";
  38. }
  39.  
  40. </script>
  41. </head>
  42. <body onload="carregar()">
  43. Esta é um exemplo de Javascript. <br/>
  44. <button onclick="clique()">Me clique</button>
  45. <p>
  46. Digite algo: <input type="text" name="valor" id="valor">
  47. <button onclick="clique2()">Clica de novo?</button>
  48. </p>
  49. <div>Vai escrever a data ao clicar <a href="#" onclick="escreve()">aqui.</a></div>
  50. <div>Vai escrever algo clicar <a href="#" onclick="escreve2()">aqui.</a></div>
  51. <span id="elemento"></span>
  52. <div>Exercício
  53. Criar uma página nova chamada calculadora.html
  54. Na tela devem conter dois inputs do tipo texto com os ids valor1 e valor2. Um terceiro input com id chamado operacao. Um botão que chame a função calcula
  55. Criar a função em javascript que leia os dois valores e execute a operação digitada (+ - * /).
  56. Mostar em um alert o resultado e em um elemento span na tela com a id resultado.
  57. </div>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement